简体   繁体   中英

How to Convert Multiple Unix TimeStamp to Pandas Datetime?

I get the following error when trying to convert multiple the unix timestamps to a datetime in pandas, I've tried setting values but seem to not be getting it right.

ValueError: to assemble mappings requires at least that [year, month, day] be specified: [day,month,year] is missing

Here's the code:

pd.to_datetime(ksdata[['state_changed_at','created_at','launched_at']])

It's got to be something simple but I just can't see it.

Sample of file

在此处输入图片说明

The dataset helps as its easier to test the solution but anyway for unix timestamp, solution would be

ksdata[['state_changed_at','created_at','launched_at']] = ksdata[['state_changed_at','created_at','launched_at']].\
apply(pd.to_datetime, unit = 's')

As @MaxU suggested, if you need to convert all the columns ending with '_at' to timestamp, you can filter them using

ksdata.filter(regex='_at$') 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM