datetime - extract hour from timestamp with python -
i have dataframe df_energy2
df_energy2.info() <class 'pandas.core.frame.dataframe'> rangeindex: 29974 entries, 0 29973 data columns (total 4 columns): timestamp 29974 non-null datetime64[ns] p_act_kw 29974 non-null int64 periode_tarif 29974 non-null object p_souscr 29974 non-null int64 dtypes: datetime64[ns](1), int64(2), object(1) memory usage: 936.8+ kb
with structure :
df_energy2.head() timestamp p_act_kw periode_tarif p_souscr 2016-01-01 00:00:00 116 hc 250 2016-01-01 00:10:00 121 hc 250
is there python fucntion can extract hour timestamp
?
kind regards
i think need dt.hour
:
print (df.timestamp.dt.hour) 0 0 1 0 name: timestamp, dtype: int64 df['hours'] = df.timestamp.dt.hour print (df) timestamp p_act_kw periode_tarif p_souscr hours 0 2016-01-01 00:00:00 116 hc 250 0 1 2016-01-01 00:10:00 121 hc 250 0
Comments
Post a Comment