python:从现有数据框,将纪元转换为可读时间戳并添加到新列
python: from an existing dataframe, convert epoch to readable timestamp and add to a new column
我是 python 的新手,我正在尝试将一列纪元时间值转换为可读的时间戳。
下面是我开始使用的数据框示例:
**COORDs Epoch_time**
-78.6496222999, 35.7928398208999 1568594961
-78.6835260145, 35.8283383364 1568591361
-78.5917963281, 35.8409603850999 1568587761
-78.6602230965, 35.8868264454999 1568584161
-78.6387225789, 35.793230819 1568573361
我想将 Epoch_time 列转换为可读的时间戳,然后添加到数据框中名为时间戳的新列。
我用过代码:df[timestamp] = pd.to_datetime(df['Epoch_time'], unit = 'ms')
并收到以下错误:
df[timestamp] = pd.to_datetime(df['Epoch_time'], unit = 'ms')
Traceback (most recent call last):
File "<ipython-input-24-a9eff940f87e>", line 1, in <module>
df[timestamp] = pd.to_datetime(df['Epoch_time'], unit = 'ms')
NameError: name 'timestamp' is not defined
感谢任何帮助。提前谢谢你。
您缺少引号,应该是 df['timestamp'] = pd.to_datetime(df['Epoch_time'], unit = 'ms')
我是 python 的新手,我正在尝试将一列纪元时间值转换为可读的时间戳。
下面是我开始使用的数据框示例:
**COORDs Epoch_time**
-78.6496222999, 35.7928398208999 1568594961
-78.6835260145, 35.8283383364 1568591361
-78.5917963281, 35.8409603850999 1568587761
-78.6602230965, 35.8868264454999 1568584161
-78.6387225789, 35.793230819 1568573361
我想将 Epoch_time 列转换为可读的时间戳,然后添加到数据框中名为时间戳的新列。
我用过代码:df[timestamp] = pd.to_datetime(df['Epoch_time'], unit = 'ms')
并收到以下错误:
df[timestamp] = pd.to_datetime(df['Epoch_time'], unit = 'ms')
Traceback (most recent call last):
File "<ipython-input-24-a9eff940f87e>", line 1, in <module>
df[timestamp] = pd.to_datetime(df['Epoch_time'], unit = 'ms')
NameError: name 'timestamp' is not defined
感谢任何帮助。提前谢谢你。
您缺少引号,应该是 df['timestamp'] = pd.to_datetime(df['Epoch_time'], unit = 'ms')