user2491254
user2491254

Reputation: 783

Selecting values from a Pandas DataFrame with a hierarchical index

I am trying to create a scatterplot of price vs. number for a certain year, say 2000.

I tried plotting with plt.plot(summary.price, summary.number, 'ro'), but I want it for a specific year so tried to only get the data from year 2000 with df['2000'] but it says key error.

How do I create a scatterplot with data from just a specific year?

enter image description here

Upvotes: 0

Views: 306

Answers (1)

joaquin
joaquin

Reputation: 85603

To get the dataframe rows for index 2000 you can use:

df.xs(2000)

Other methods for selecting your data by the label of the index are:

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

enter image description here

Check Pandas docs for more information

Upvotes: 1

Related Questions