問題描述
如何將python中的數據框列對象轉換為日期時間格式 (How to convert a dataframe column object in python to date time format)
如何使用 pandas 將數據框中對像數據類型的列值轉換為 python 中的日期時間格式?
給出下面我得到的樣本值,當我執行 print(df['timestamp'])
以供參考
0 2020‑02‑03 18:00:33
1 2020‑02‑03 18:00:37
2 2020‑02‑03 18:00:39
br /> 3 2020‑02‑03 18:01:16
4 2020‑02‑03 18:01:17
5 2020‑02‑03 18:02:14
6 2020 ‑02‑03 18:02:46
7 2020‑02‑03 18:02:50
8 2020‑02‑03 18:02:58
請注意
- 列時間戳的數據類型為對象
參考解法
方法 1:
df['ColumnName'] = pd.to_datetime(df['ColumnName'])
(by Sunish、awfullyCold)