我想把几天放在我的数据时间格式上。在其他应用程序上,我使用了以下内容:
df2.Timestamp = pd.to_datetime(df2.Timestamp,dayfirst=True) #the format is d/m/yyyy
现在,我想使用Apply函数,因为我有不止一列,而不是四行地执行,我想使用Apply在一行中完成。
df2[["Detection_time", "Device_ack", "Reset/Run", "Duration"]] = df2[["Detection_time", "Device_ack", "Reset/Run", "Duration"]].apply(pd.to_datetime)
但是我不知道如何配置“ dayfirst”参数。
最佳答案
您可以使用:
(df2[["Detection_time", "Device_ack", "Reset/Run", "Duration"]]
.apply(pd.to_datetime,dayfirst=True))
关于python - 使用apply和datetime函数时如何写日期格式?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57427747/