pandas 将utc字符串转换为日期时间

ddrv8njm  于 2023-09-29  发布在  其他
关注(0)|答案(1)|浏览(100)

尝试下面的代码将utc字符串转换为datetinme,但不工作:

import pandas as pd

data = [
    ["2023-09-13T19:17:21.000Z"],
    ["2023-09-13T19:18:22.000Z"],
    ["2023-09-13T19:19:23.000Z"],
    ]
    
df = pd.DataFrame(data,columns=['ts'])
df['ts'] = pd.to_datetime(df['ts'],format='%Y-%m-%dT%H:%M:%S.%Z')
print(df)
zzlelutf

zzlelutf1#

为什么这行不通?

import pandas as pd

data = [
    ["2023-09-13T19:17:21.000Z"],
    ["2023-09-13T19:18:22.000Z"],
    ["2023-09-13T19:19:23.000Z"],
]
    
df = pd.DataFrame(data, columns=['ts'])
df['ts'] = pd.to_datetime(df['ts']) # remove the formatting used earlier
print(df)

相关问题