Chart with Seaborn with one of the axes being the index

Asked

Viewed 407 times

-1

I have a dataframe, it has a standard index, but replace this standard index by the name of the Brazilian states and now I would like to plot a Plot bar vertical, using the Y axis with the name of the states (index values) and the X axis as a value of deaths per state. But Seraborn is returning me a mistake that I am not able to interpret.

Dataframe

Código do Seaborn

Erro retornado

2 answers

1

Felipe, the barplot method cannot interpret 'covid_By_state.index' because its dataframe has no column with this name. Create a column with another name (state, for example) and feed it the states that are indexing your dataframe. This should solve.

Here’s a similar example where I plotted the data by region.

fig3, ax3 = plt.subplots(1,1,figsize=(10,6))
sns.barplot(data=pd.DataFrame({
    'TotalCasos':maxByReg,
    'Região':aadf.Região.unique()}),
     x='Região',y='Total Casos',palette='rainbow')
ax3.set_xlabel('Região ',size='x-large')
ax3.set_ylabel('Total de casos (30-03)', size='x-large')

Just a tip: try to share your datasets and your codes with us. Screen shots don’t make your work much easier.

exemplo

I hope you managed to solve your problem, hug.

  • Thank you for the reply comrade!

1


I went through the same situation today.

plt.figure(figsize=(20,10))
sns.barplot(data=df, x='mortes_confirmadas', y=df.index)
plt.show()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.