Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert pandas._libs.tslibs.timestamps.Timestamp to datetime

Tags:

python

pandas

I want to convert this Timestamp object to datetime this object was obtained after using asfreq on a dataframe this is the last index

Timestamp('2018-12-01 00:00:00', freq='MS')
<class 'pandas._libs.tslibs.timestamps.Timestamp'>

wanted output

2018-12-01
like image 215
Ali Avatar asked Sep 21 '25 01:09

Ali


1 Answers

do you want this?

from pandas._libs.tslibs.timestamps import Timestamp
ts = Timestamp('2018-12-01 00:00:00', freq='MS')
date_time = ts.to_pydatetime()

And if you just want a string then you can do this:

print(str(ts).split()[0])

out:

'2018-12-01'
like image 58
Peyman Avatar answered Sep 22 '25 16:09

Peyman