【发布时间】:2018-10-01 14:52:32
【问题描述】:
我一直在寻找解决问题的方法。
我使用下面的代码从我想要的列中获取数据
import pandas as pd
df = pd.read_excel("Live_data_test.xlsx","Sheet1")
number_of_entries = len(df.loc[:, 'Time'])
number_of_entries_last_3 = number_of_entries - 3
unix_x1 = df.loc[number_of_entries_last_:number_of_entries, 'Time']
print(unix_x1)
我得到了输出
10 1.513753e+09
11 1.513753e+09
12 1.513753e+09
Name: Time, dtype: float64
我想将此时间转换为可读时间,以便将其输入到 matplotlib 图形的 x 轴中。
real_x1 = datetime.datetime.strptime(str(unix_x1), '%Y-%m-%d %H:%M:%S')
我得到了错误
ValueError: time data '10 1.513753e+09\n11 1.513753e+09\n12 1.513753e+09\nName: Time, dtype: float64' does not match format '%Y-%m-%d %H:%M:%S'
如何让这个 unix 时间输出为用户可读的格式?
我对代码有点陌生,所以如果你回答,如果可以的话,你能解释一下原因吗?
【问题讨论】:
标签: python excel pandas matplotlib