quant
quant

Reputation: 4492

how to transform YYMMDDHH timestamp in date python

I have the following timestamps

 import pandas as pd
        import pandas as pd
df = pd.DataFrame({'ts':[14102100, 14102101, 14102102]})

And they are in format YYMMDDHH.

How can I transform them into a readable date ?

I tried pd.to_datetime(df.ts, format="YYMMDDHH") but it doesnt work

Upvotes: 2

Views: 331

Answers (1)

jezrael
jezrael

Reputation: 863361

I think you need formats with % by http://strftime.org/:

df = pd.DataFrame({'ts':[14102100, 14102101, 14102102]})

print (pd.to_datetime(df.ts, format="%y%m%d%H"))
0   2014-10-21 00:00:00
1   2014-10-21 01:00:00
2   2014-10-21 02:00:00
Name: ts, dtype: datetime64[ns]

Upvotes: 3

Related Questions