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..
You can use datetime accessor and extract month
df['month'] = df['Date_Time'].dt.month
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With