简体   繁体   中英

chnage a unix base timestamp column into time

I have a column named timestamp in dataframe which extends for 30000 rows I want to change the unit value of the column to time and date.

The first value is 1590000000000 and is going down with same or different values. I want to have the new df to have the timestamp depicted as time and date.

How do we do this this in python?

您可以尝试使用pd.to_datetime(df['mydates']).apply(lambda x: x.date())

You can use pandas.to_datetime method to convert the unix based timestamp to your required date-time format. Note: Here I am assuming that this timestamp is in millisecond(ms) .

Try this:

df["timestamp"] = pd.to_datetime(df["timestamp"], unit="ms")

Output:

                timestamp
0 2020-05-20 18:40:00.000
...
...

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