Pandas - Creating a Pair Plot using Seaborn for Multiple variable analysis
Pandas: Visualization Integration Exercise-6 with Solution
Write a Pandas program to create a Pair Plot with Seaborn.
This exercise demonstrates how to create a pair plot using Seaborn to visualize relationships between all numerical columns in a DataFrame.
Sample Solution :
Code :
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Create a sample DataFrame
df = pd.DataFrame({
'Height': [150, 160, 170, 180, 190],
'Weight': [50, 60, 70, 80, 90],
'Age': [22, 25, 30, 35, 40]
})
# Create a pair plot to visualize relationships between columns
sns.pairplot(df)
# Display the plot
plt.show()
Output:
Explanation:
- Created a DataFrame with numerical columns.
- Used sns.pairplot() to generate scatter plots for every pair of numerical columns, visualizing the relationships.
- Displayed the resulting pair plot.
Python-Pandas Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://198.211.115.131/python-exercises/pandas/pandas-create-a-pair-plot-using-seaborn-for-multiple-variable-analysis.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics