Data visualization with Pairplot Seaborn and Pandas - GeeksforGeeks

22 Jun, 2021
Data Visualization is the presentation of data in pictorial format. It is extremely important for Data Analysis, primarily because of the fantastic ecosystem of data-centric Python packages. And it helps to understand the data, however, complex it is, the significance of data by summarizing and presenting a huge amount of data in a simple and easy-to-understand format and helps communicate information clearly and effectively.
Pandas and Seaborn is one of those packages and makes importing and analyzing data much easier. In this article, we will use Pandas and Pairplot Seaborn to analyze data.
Pandas Offer tools for cleaning and process your data. It is the most popular Python library that is used for data analysis. In pandas, a data table is called a dataframe.
So, let’s start with creating a Pandas data frame:
Example 1:
Python3
# Python code demonstrate creating     import pandas as pd    # initialise data of lists.data = {'Name':[ 'Mohe' , 'Karnal' , 'Yrik' , 'jack' ],        'Age':[ 30 , 21 , 29 , 28 ]}    # Create DataFramedf = pd.DataFrame( data )    # Print the output.display(df)
 
 
Output:
 
 
Example 2: load the CSV data from the system and display it through pandas.
 
Python3
# import moduleimport pandas # load the csvdata = pandas.read_csv("nba.csv") # show first 5 columndata.head()
 
 
Output:
 
 
To plot multiple pairwise bivariate distributions in a dataset, you can use the pairplot() function. This shows the relationship for (n, 2) combination of variable in a DataFrame as a matrix of plots and the diagonal plots are the univariate plots.
 
Syntax: seaborn.pairplot( data, \*\*kwargs )
Parameter:
data: Tidy (long-form) dataframe where each column is a variable and  each row is an observation.
hue: Variable in “data“ to map plot aspects to different colors.
palette: dict or seaborn color palette
{x, y}_vars: lists of variable names, optional
dropna: boolean, optional
 
Example 1: 
 
Python3
# importing packagesimport seabornimport matplotlib.pyplot as plt # loading dataset using seaborndf = seaborn.load_dataset('tips') # pairplot with hue sexseaborn.pairplot(df, hue ='size')plt.show()
Output:
We see how to create pandas dataframe and Pairplot. We will visualize data with pairplot using pandas
Example 1: 
In this example, we will simply plot a pairplot with pandas data frame. Here we are simply loading nba.csv data and creating a dataframe and although passing as arguments in a pairplot.
Python3
# importing packagesimport seabornimport pandas # load the csvdata = pandas.read_csv("nba.csv") # pairplotseaborn.pairplot(data)
Output:
Example 2:
In this example, we will be going to use hue attributes for the visualization of a specific column.
Python3
# importing packagesimport seabornimport pandas # load the csvdata = pandas.read_csv("nba.csv")seaborn.pairplot(data.head(), hue = 'Age')
Output:
Example 3:
In this example, we will pass the dictionaries of keyword arguments for bivariate plotting function(plot_kws and diag_kws)
Python3
# importing packagesimport seabornimport pandas# load the csvdata = pandas.read_csv("nba.csv") seaborn.pairplot(data, hue = 'Age', diag_kind = 'kde',             plot_kws = {'edgecolor': 'k'}, size = 4)
 
 
Output:
 
 
sooda367
Data Visualization
Python-pandas
Python-Seaborn
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Read JSON file using Python
Adding new column to existing DataFrame in Pandas
Python map() function
How to get column names in Pandas dataframe
Python Dictionary
Taking input in Python
Read a file line by line in Python
Enumerate() in Python
How to Install PIP on Windows ?
Iterate over a list in Python