如何将所有数据框列值转换为 ISO-8601 格式当我执行print(df['timestamp'])以供参考时,给出低于我得到的样本值0 2020-02-03 18:00:331 2020-02-03 18:00:372 2020-02-03 18:00:393 2020-02-03 18:01:164 2020-02-03 18:01:175 2020-02-03 18:02:146 2020-02-03 18:02:467 2020-02-03 18:02:508 2020-02-03 18:02:58低于 预期结果0 2020-02-03T18:00:33-061 2020-02-03T18:00:37-062 2020-02-03T18:00:39-063 2020-02-03T18:01:16-064 2020 -02-03T18:01:17-065 2020-02-03T18:02:14-06 6 2020-02-03T18:02:46-067 2020-02-03T18:02:50-068 2020-02 -03T18:02:58-06
1 回答
墨色风雨
TA贡献1853条经验 获得超6个赞
df = pd.DataFrame() df['timestamp'] = pd.date_range('2018-01-01', periods=10, freq='H')
如果您只想以 isoformat 输出:
df['timestamp'].map(lambda x: x.isoformat())
如果要创建一个额外的列:
df['iso_timestamp'] = df['timestamp'].map(lambda x: x.isoformat())
如果要覆盖:
df['timestamp'] = df['timestamp'].map(lambda x: x.isoformat())
添加回答
举报
0/150
提交
取消