熊猫密谋问题

时间:2015-03-23 15:24:25

标签: python pandas matplotlib

我有以下数据框:

Price,Volume
6550,18
6551,5
6552,2
6553,13
......
......
......
7001,3
7002,21

我希望沿着一个轴的价格和另一个的价格。由于这是一个大熊猫数据帧,我的印象是我可以按如下方式绘制:

df.plot(kind='bar')
plt.show()

然而,它正在沿同一轴绘制两列。我希望每列都在一个单独的轴上。我尝试过以下哪些不起作用:

df.plot(kind='bar', xticks=df['Price'], yticks=df['Volume'])

任何关于我做错事的建议都会受到赞赏。

2 个答案:

答案 0 :(得分:1)

使用df.plot(kind='bar')绘图时,它将使用x轴的索引,然后将DataFrame中的所有列绘制为y值。

要解决此问题,you can choose x and y values to be used,例如:

df.plot(x='Price', y='Volume', kind='bar')

有关使用pandas进行绘图的更多示例,请参阅here

答案 1 :(得分:1)

通过标签指定所需的x和y:

df.plot(x='Price', y='Volume', kind='bar')

以下是完整的文档:

http://pandas.pydata.org/pandas-docs/dev/generated/pandas.DataFrame.plot.html

相关问题