Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting Error 0 when plotting boxplot of a filtered dataset

I am working on Abalone dataset and I am facing a weird problem when plotting a boxplot.

If a run:

plt.figure(figsize=(16,6))
plt.subplot(121)
sns.boxplot(data=df['rings'])

working perfectly!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If I filter the dataset by sex like this:

df_f = df[df['sex']=='F']
df_m = df[df['sex']=='M']
df_i = df[df['sex']=='I']

And i run:

plt.figure(figsize=(16,6))
plt.subplot(121)
sns.boxplot(data=df_m['rings'])

working perfectly!

But if I run the code above for df_f and df_i datasets I get an error:

KeyError: 0

There’s no missing values, all values are int.

What I am missing here?

>Solution :

If you want a box plot per value of a categorical column I suggest:

sns.boxplot(data=df, x='rings', y='sex')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading