Pandas Convert Hour Index Integer To Datetime
i have a Pandas dataframe like this: Date Hour Actual 2018-06-01 0 0.000000 2018-06-01 1 0.012000 2018-06-01 2 0.065000 2018-06-01 3 0.560000 ... I want to
Solution 1:
Use to_datetime
with to_timedelta
and pop
for extract column time
:
df['Date'] = pd.to_datetime(df['Date']) + pd.to_timedelta(df.pop('Hour'), unit='H')
print (df)
Date Actual
0 2018-06-01 00:00:00 0.000
1 2018-06-01 01:00:00 0.012
2 2018-06-01 02:00:00 0.065
3 2018-06-01 03:00:00 0.560
Post a Comment for "Pandas Convert Hour Index Integer To Datetime"