我一直在寻找很长时间来找到解决我的问题的方法。
我使用以下代码从想要的列中获取数据
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)
Run Code Online (Sandbox Code Playgroud)
我得到了输出
10 1.513753e+09
11 1.513753e+09
12 1.513753e+09
Name: Time, dtype: float64
Run Code Online (Sandbox Code Playgroud)
我想将此时间转换为可读时间,以便将其输入到matplotlib图的x轴中。
real_x1 = datetime.datetime.strptime(str(unix_x1), '%Y-%m-%d %H:%M:%S')
Run Code Online (Sandbox Code Playgroud)
我得到错误
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'
Run Code Online (Sandbox Code Playgroud)
我如何获得这个unix时间来输出为用户可读的格式?
我对代码有点陌生,所以如果您回答,是否可以解释原因?