我想用时间戳和另一列来绘制Excel数据。 x =时间 y ='找到'
Excel看起来像这样:
Read_in.xlsx:
Index Timestamp Find
0
1 *useless information*
2 Timestamp *useless information'
3 2012-07-16 12:00:00 2,31
4 2012-07-16 12:05:00 2,33
5 2012-07-16 12:10:00 2,22
...
1447 2012-07-21 12:00:00 2,44
我尝试了以下代码:
import pandas as pd
import matplotlib.pyplot as plt
datei= pd.read_excel('Read_in.xlsx', sheet_name= 'Data')
daten=datei.filter(regex='Find')
Time=datei['Timestamp']
Time=Time.dropna(axis=0)
Time=Time.to_string()
x=Time
y= daten
plt.plot(x,y)
ValueError:x和y必须具有相同的第一维度,但形状为(1,)和(1448,2)
答案 0 :(得分:0)
您可以将to_datetime
与errors='coerce'
一起使用,以将nopn datetimelike值替换为NaT
,然后使用to_numeric
将,
替换为.
:< / p>
datei['Timestamp'] = pd.to_datetime(datei['Timestamp'], errors='coerce')
datei['Find'] = pd.to_numeric(datei['Find'].str.replace(',','.'), errors='coerce')
#if format of numbesr is 2.31
#datei['Find'] = pd.to_numeric(datei['Find'], errors='coerce')
datei = datei.dropna()
print (datei)
Timestamp Find
3 2012-07-16 12:00:00 2.31
4 2012-07-16 12:05:00 2.33
5 2012-07-16 12:10:00 2.22
datei.plot(x='Timestamp', y='Find')
或者:
x=datei['Timestamp']
y= datei['Find']
plt.plot(x,y)