如何將所有數據框列值轉換為 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
提交
取消