2
How can I convert a Dataframe column from Timestamp to Datetime?
btc_df = pd.DataFrame ( bars_day , columns=['date' , 'volume' , 'open' , 'high' , 'low' , 'close'] )
Summary
date int64
volume object
open object
high object
low object
close object
dtype: object
volume open ...
date ...
1610323200000 38150.02 38264.74 ...
1610409600000 35410.37 36628.00 ...
1610496000000 34049.15 37850.00 ...
1610582400000 37371.38 40100.00 ...
1610668800000 39145.21 39747.76 ...
Thank you!
Thanks for the reply however how can I get the date + time? Any recommendations?
– LEANDRO FIGUEIRA
@LEANDROFIGUEIRA, good afternoon! You can use the
pd.to_datetime(df['Date'])
. Hug!– lmonferrari
This I’m not getting: '' btc_df['date'] = btc_df['date']. astype('datetime64[ns]') 1970-01-01 00:26:50.323200 btc_df['date'] = btc_df['date']. astype('datetime64[ms]') 2021-01-11 btc_df['date'] = pd.to_datetime(btc_df['date']) 1970-01-01 00:26:50.323200 '' You cannot return in the same date+time object?
– LEANDRO FIGUEIRA
@LEANDROFIGUEIRA Its time is a set of zeros, so the pandas 'eliminates' the hour. If you put for example 1 in the last number it will return you the date and time (do a test). With the dates you have there you have to treat them as ms, as we would need to have more numbers on your timestamp. Hug!
– lmonferrari