我有一个存储各种熊猫数据帧的列表。我打算从列表中打印一个数据框,但是获得的图是空的。
import pandas as pd
Y6= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
Y6=pd.DataFrame(data=Y6)
dfs = list()
for x in range(0, len(Y6), 10):
df = Y6.iloc[x:x+10].T
#df.columns= ['one','two']
dfs.append(df)
for df in dfs:
print(df)
print()
print(dfs[0])
plt.plot(dfs[0])
#Obtained output
[<matplotlib.lines.Line2D at 0x1f190f81710>,
<matplotlib.lines.Line2D at 0x1f190f81908>,
<matplotlib.lines.Line2D at 0x1f190f81b00>,
<matplotlib.lines.Line2D at 0x1f190f81cf8>,
<matplotlib.lines.Line2D at 0x1f190f81ef0>,
<matplotlib.lines.Line2D at 0x1f190eef128>,
<matplotlib.lines.Line2D at 0x1f190eef320>,
<matplotlib.lines.Line2D at 0x1f190eef518>,
<matplotlib.lines.Line2D at 0x1f190eef710>,
<matplotlib.lines.Line2D at 0x1f190eef908>]
答案 0 :(得分:0)
您可以绘制10条线(每条线仅包含一个点),而不是绘制10条线。由于一条线至少需要包含两个点,因此绘图上没有任何显示。
请考虑不要转置您的数据框,以使其停留在单列中。然后按预期进行绘制。
import pandas as pd
import matplotlib.pyplot as plt
Y6= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
Y6=pd.DataFrame(data=Y6)
dfs = list()
for x in range(0, len(Y6), 10):
df = Y6.iloc[x:x+10]
dfs.append(df)
plt.plot(dfs[0])
plt.show()