I am trying to display in a subplot all the boxplots corresponding to each columns in my dataframe df.
I have read this question: Subplot for seaborn boxplot and tried to implement the given solution:
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
d = {'col1': [1, 2, 5.5, 100], 'col2': [3, 4, 0.2, 3], 'col3': [1, 4, 6, 30], 'col4': [2, 24, 0.2, 13], 'col5': [9, 84, 0.9, 3]}
df = pd.DataFrame(data=d)
names = list(df.columns)
f, axes = plt.subplots(round(len(names)/3), 3)
y = 0;
for name in names:
sns.boxplot(x= df[name], ax=axes[y])
y = y + 1
Unfortunately I get an error
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-111-489a538377fc> in <module> 3 y = 0; 4 for name in names: ----> 5 sns.boxplot(x= df[name], ax=axes[y]) 6 y = y + 1 AttributeError: 'numpy.ndarray' object has no attribute 'boxplot'
I understand there is a problem with df[name]
but I can't see how to fix it.
Would someone be able to point me in the right direction?
Thank you very much.