Timestamp string (Unix time) in datetime or pandas.Timestamp

From the source I am extracting some data in JSON format. I want to save this data (measurements over time) as a text file. Repeatedly I want to go to the same source and see if new dimensions are available, so I want to add it to other dimensions.

The data obtained is as follows:

{"xyz":[{"unixtime":"1458255600","time":"00:00","day":"18\/03","value":"11","paramlabel":"30-500 mHz","popupcorr":"550","iconnr":"7","paramname":"30-500 mHz"},{"unixtime":"1458256200","time":"00:10","day":"18\/03","value":"14","paramlabel":"30-500 mHz","popupcorr":"550","iconnr":"7","paramname":"30-500 mHz"},etc.]}

I load this data into a pandas DataFrame to be able to work with it more easily. However, when I load this into a dataframe, all columns are treated as rows. How can I make sure that the unixtime column is treated as a timestamp (so that I can convert to datetime)?

+4
source share
1 answer

use to_datetimeand pass unit='s'for processing values ​​as time of an era after conversion dtypeto intusing astype:

df['unixtime'] = pd.to_datetime(df['unixtime'].astype(int), unit='s')

Example:

In [162]:
pd.to_datetime(1458255600, unit='s')

Out[162]:
Timestamp('2016-03-17 23:00:00')
+5
source

All Articles