Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'Int64Index' object has no attribute 'month'

I have some time series data with three separate colums (Date, Time, kW) that looks like this:

Date     Time        kW
3/1/2011 12:15:00 AM 171.36
3/1/2011 12:30:00 AM 181.44
3/1/2011 12:45:00 AM 175.68
3/1/2011 1:00:00 AM 180.00
3/1/2011 1:15:00 AM 175.68

And reading the csv file directly from Pandas I can parse the Date & Time:

df= pd.read_csv('C:\\Users\\desktop\\master.csv', parse_dates=[['Date', 'Time']])

Which appears to work nicely, but the problem is I want to create another data frame in Pandas to represent the numerical value of the month. If I do a:

df['month'] = df.index.month

An error is thrown:

AttributeError: 'Int64Index' object has no attribute 'month'

I am also hoping to create additional dataframes to represent time stampt day, minute, hour... Any tips greatly appreciated..

like image 668
bbartling Avatar asked Nov 07 '22 20:11

bbartling


1 Answers

You can use datetime accessor and extract month

df['month'] = df['Date_Time'].dt.month
like image 101
Vaishali Avatar answered Nov 11 '22 15:11

Vaishali