I am creating probability distributions for each column of my data frame by distplot from seaborn library sns.distplot(). For one plot I do
x = df['A']
sns.distplot(x);
I am trying to use the FacetGrid & Map to have all plots for each columns at once in this way. But doesn't work at all.
g = sns.FacetGrid(df, col = 'A','B','C','D','E')
g.map(sns.distplot())
I think the easiest approach is to just loop the columns and create a plot.
I think you need to use
melt
to reshape your dataframe to long format, see this MVCE:Output:
You're getting this wrong on two levels.
Python syntax.
FacetGrid(df, col = 'A','B','C','D','E')
is invalid, becausecol
gets set toA
and the remaining characters are interpreted as further arguments. But since they are not named, this is invalid python syntax.Seaborn concepts.
Seaborn expects a single column name as input for the
col
orrow
argument. This means that the dataframe needs to be in a format that has one column which determines to which column or row the respective datum belongs.You do not call the function to be used by map. The idea is of course that
map
itself calls it.Solutions:
Loop over columns:
Melt dataframe