Skip to content Skip to sidebar Skip to footer

Using Pandas To_datetime With Timestamps

I'm trying to covert my these timestamps into a %Y-%m-%d %H:%M format. Here's a sample of the data: 0 1450753200 1 1450756800 2 1450760400 3 1450764000 4 1450767600

Solution 1:

Pass unit='s' to get the values as it's epoch time:

In [106]:
pd.to_datetime(df['timestamp'], unit='s')
Out[106]:
index
0   2015-12-22 03:00:00
1   2015-12-22 04:00:00
2   2015-12-22 05:00:00
3   2015-12-22 06:00:00
4   2015-12-22 07:00:00
Name: timestamp, dtype: datetime64[ns]

You can convert to string if you desire:

In [107]:

pd.to_datetime(df['timestamp'], unit='s').dt.strftime('%Y-%m-%d %H:%M')
Out[107]:
index
0    2015-12-22 03:00
1    2015-12-22 04:00
2    2015-12-22 05:00
3    2015-12-22 06:00
4    2015-12-22 07:00
Name: timestamp, dtype: object

Post a Comment for "Using Pandas To_datetime With Timestamps"