How to combine two dataframes into pairplot?
Question:
I have two dataframes df1 and df2 in Python, transformed from a numpy array in which df1 has 50 rows and 8 columns and df2 10 rows and 8 columns as well, and I would like to use pairplot to see these values. I have made something like this:
df1=pd.DataFrame(data1)
df2=pd.DataFrame(data2)
sns.pairplot(df1)
sns.pairplot(df2)
plt.show()
But I would like that the points or histograms of the df2 to appear superimpose, for example, in red color to the df1 points which are in blue. How can I do that?
Answers:
Using hue
parameter in seaborn you can choose column that will differ them.
sns.pairplot(joined_df,hue='special_column_to_differ_df')
But you will have to join them first.
To illustrate problem I use iris
dataset.
First produce 2 dataframes:
import seaborn as sns
iris = sns.load_dataset("iris")
df1 = iris[iris.species =='setosa']
df2 = iris[iris.species =='versicolor']
We have now Your starting point. Then concatenate dataframes and plot the result:
df12 = df1.append(df2)
g = sns.pairplot(df12, hue="species")
use hue
parameter to separate points by color.
I have two dataframes df1 and df2 in Python, transformed from a numpy array in which df1 has 50 rows and 8 columns and df2 10 rows and 8 columns as well, and I would like to use pairplot to see these values. I have made something like this:
df1=pd.DataFrame(data1)
df2=pd.DataFrame(data2)
sns.pairplot(df1)
sns.pairplot(df2)
plt.show()
But I would like that the points or histograms of the df2 to appear superimpose, for example, in red color to the df1 points which are in blue. How can I do that?
Using hue
parameter in seaborn you can choose column that will differ them.
sns.pairplot(joined_df,hue='special_column_to_differ_df')
But you will have to join them first.
To illustrate problem I use iris
dataset.
First produce 2 dataframes:
import seaborn as sns
iris = sns.load_dataset("iris")
df1 = iris[iris.species =='setosa']
df2 = iris[iris.species =='versicolor']
We have now Your starting point. Then concatenate dataframes and plot the result:
df12 = df1.append(df2)
g = sns.pairplot(df12, hue="species")
use hue
parameter to separate points by color.