0

I have a data that contains suicides, year by year and country by country and more. I grouped them by age and country but by doing that i think country and age are becoming indexes and that is why I cant use them on barplot. Here is the code.

spe = df.groupby(['country','age']).sum().sort_values(by='suicides_no').xs(level='age',
                                                                          key='15-24 years')
sns.barplot(x = 'country', y = 'suicides_no',data = spe)
matplotlib.pyplot.xticks(rotation=90)

I get this error:

ValueError: Could not interpret input 'country'

2 Answers 2

1

You can turn indicies back into columns spe = spe.reset_index()

Sign up to request clarification or add additional context in comments.

Comments

0

If you are plotting just one group of age as your spe indicates, you can just do:

(df[df['age']=='15-24 years'].groupby('country', as_index=False)
     .sort_values('suicides_no')
     .plot.bar(x='country', y='suicides_no')
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.