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]:index02015-12-22 03:00:0012015-12-22 04:00:0022015-12-22 05:00:0032015-12-22 06:00:0042015-12-22 07:00:00Name: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]:index02015-12-22 03:0012015-12-22 04:0022015-12-22 05:0032015-12-22 06:0042015-12-22 07:00Name:timestamp,dtype:object

Post a Comment for "Using Pandas To_datetime With Timestamps"