Skip to content Skip to sidebar Skip to footer

Pandas - Data Series - TypeError: Index Must Be DatetimeIndex

C is a Data series with shape of (10000000, ) with dtypes of dtype(< M8[ns]). I want to create a dataseries which only contain one hour of C. c.between_time('22:00:00','23:00:

Solution 1:

Try creating a dataframe by initializing an empty dataframe.
I created a sample of 3 dummy times in Series

import pandas as pd  
C = pd.Series(['22:00:00','22:30:00','23:00:00'])

df = pd.DataFrame()
df['C'] = C

#set index to the obervations after converting them to type datetimeIndex
df.index = pd.to_datetime(C)
print df

print df.between_time(df['C'][0],df['C'][2])

Post a Comment for "Pandas - Data Series - TypeError: Index Must Be DatetimeIndex"