'Seaborn boxplot for classification with pandas wide to long [duplicate]
I have data that I would like to train an ml classifier on. The data is in wide format. I'd like to do a boxplot with searborn sns.boxplot(x='variable',y='value', hue='target', data=df_train). How do I reshape the data to be able to pass it to sns.boxplot?
Sample data
import pandas as pd
from sklearn import datasets
X, y = datasets.make_classification(n_samples=100, n_features=5, random_state=1)
df_train = pd.DataFrame(X)
df_train['y']=y
Solution 1:[1]
pd.melt is what you want to use.
dfg_train = df_train.melt(id_vars='y')
sns.boxplot(x='variable',y='value', hue='y', data=dfg_train)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | citynorman |
