简体   繁体   English

将 Unix 基本时间戳列更改为时间

[英]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.我在数据框中有一个名为timestamp的列,它扩展了 30000 行我想将列的单位值更改为时间和日期。

The first value is 1590000000000 and is going down with same or different values.第一个值是1590000000000并且以相同或不同的值下降。 I want to have the new df to have the timestamp depicted as time and date.我想让新的 df 将时间戳记为时间和日期。

How do we do this this in python?我们如何在 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.您可以使用pandas.to_datetime方法将基于 unix 的时间戳转换为您所需的日期时间格式。 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
...
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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