我有一个Windows事件日志,它在一个ElasticSearch集群中。我正在使用Pandas通过API查询ES。datetime字段的输出最初是一个“对象”。使用pandas.to_datetime,我已经成功地将它转换为"datetime64ns,UTC“的数据类型。
但是,字段中的数据采用不需要的格式yyyy-mm-dd hh:mm:ss+00:00。
我不想要"+00:00“那部分。我已经尝试了pandas.to_datetime的格式,但没有用。下面是我如何转换对象的方法。
services["datetime"]=pd.to_datetime(services["datetime"])这是现场输出,2020-08-31 11:02:03+00:00这里是所需的输出,08/31/2020 11:02:03
不知道怎么去那里。
发布于 2020-09-24 04:35:54
再走一步:
services["datetime"] = pd.to_datetime(services["datetime"])
services["datetime"] = services["datetime"].dt.strftime("%m/%d/%Y %H:%M:%S")发布于 2020-09-24 04:35:58
这不是纳秒,而是时区。这是熊猫日期时间的一部分,而+00:00只表示世界协调时的时间。
有几种方法可以消除熊猫的时区意识。看看这些问题:
How to remove timezone from a Timestamp column in a pandas dataframe
Convert pandas timezone-aware DateTimeIndex to naive timestamp, but in certain timezone
https://stackoverflow.com/questions/64032581
复制相似问题