没有指定索引的熊猫绘图



给定数据:

Column1; Column2; Column3
1; 4; 6
2; 2; 6
3; 3; 8
4; 1; 1
5; 4; 2

我可以通过:

import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('test0.csv',delimiter='; ', engine='python')
titles = list(df)
for title in titles:
    if title == titles[0]:
        continue
    df.plot(titles[0],title, linestyle='--', marker='o')
    plt.savefig(title+'.png')

但是,如果数据缺失Column1,如:

Column2; Column3
4; 6
2; 6
3; 8
1; 1
4; 2

我如何绘制它?

可能是df.plot(title, linestyle='--', marker='o') ?

我不知道你想要实现什么,但你可以重置索引并设置它,因为你想:

In[11]: df
Out[11]: 
   Column1   Column2   Column3
0        1         4         6
1        2         2         6
2        3         3         8
3        4         1         1
4        5         4         2

如果你想把col2画成X轴3画成Y轴你可以这样做:

df.set_index('Column2')['Column3'].plot()

最新更新