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!
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')