从具有分层索引的Pandas DataFrame中选择值

时间:2014-09-20 18:22:22

标签: python pandas

我试图创建一个特定年份的价格与数字的散点图,比如说2000年。

我尝试使用plt.plot(summary.price,summary.number,'ro')进行绘图,但是我希望它在特定的一年中,所以试图只用2000年的df ['2000']来获取数据但是它说关键错误。

如何使用特定年份的数据创建散点图?

enter image description here

1 个答案:

答案 0 :(得分:1)

要获取索引2000的数据帧行,您可以使用:

df.xs(2000)

通过索引标签选择数据的其他方法是:

df.loc[2000]   # label based
df.ix[2000]    # label and position based 

enter image description here

检查Pandas docs以获取更多信息