Skip to content
Advertisement

Datetime object in DataFrame with just time

This is the plain column

JavaScript

And the I would like to put that column in the index, the problem is when I try to use the method resample() I always get the same problem:

TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘Index’

I’ve been using this to change the Time column to

JavaScript

Advertisement

Answer

You can use set_index to set the Time column as your index of the dataframe.

JavaScript

Update after OP’s comment

If you don’t have a date column, so pandas will attach a default date 1900-01-01 when you convert it to datetime. Like this:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement