I have a dataframe and I want a function to convert the days in days of year(365). Thanks in advance.!!
d_w_data.drop(['kwh', 'time', 'month', 'dewptm', 'hum', 'wspdm', 'cos(hour)', 'sin(hour)'], inplace=True, axis=1)
d_w_data
Out[55]:
year day index1 aptemp maptemp mtempm tempm hour_to_rad
2012-04-12 14:00:00 2012 12 2012-04-12 14:00:00 17.574044 14.483582 15.508494 19.510000 3.665191
2012-04-12 15:00:00 2012 12 2012-04-12 15:00:00 17.769016 14.483582 15.508494 19.600000 3.926991
2012-04-12 16:00:00 2012 12 2012-04-12 16:00:00 17.532051 14.483582 15.508494 19.488235 4.188790
2012-04-12 17:00:00 2012 12 2012-04-12 17:00:00 16.975478 14.483582 15.508494 18.690000 4.450590
2012-04-12 18:00:00 2012 12 2012-04-12 18:00:00 16.520319 14.483582 15.508494 17.566667 4.712389
2012-04-12 19:00:00 2012 12 2012-04-12 19:00:00 15.481347 14.483582 15.508494 16.778125 4.974188
2012-04-12 20:00:00 2012 12 2012-04-12 20:00:00 15.361154 14.483582 15.508494 16.275862 5.235988
2012-04-12 21:00:00 2012 12 2012-04-12 21:00:00 15.084252 14.483582 15.508494 15.584211 5.497787
Yes the dataframe is pandas and I want to convert days in days of year(1-365). I want to do a load forecasting.Thank you!!
If you parse your dates to struct_time
you'll get days of year as an attribute.
>>>import time
>>>time.strptime("18 Jun 15", "%d %b %y")
time.struct_time(tm_year=2015, tm_mon=6, tm_mday=18, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=169, tm_isdst=-1)
So:
>>>import time
>>>time.strptime("18 Jun 15", "%d %b %y").tm_yday
169
You don't have to leave pandas to do this.
dti = pd.date_range('05-01-1990', '05-31-1990')
dti.dayofyear
returns
array([121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133,
134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
147, 148, 149, 150, 151], dtype=int32)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.