How to use seaborn to visualise a Pandas dataframe?

This recipe helps you use seaborn to visualise a Pandas dataframe

Recipe Objective

Have you ever feel a need to visualize the data in various form. Visualizing the data give us a better idea how our dataset is distributed.

So this is the recipe on how we use seaborn to visualise a Pandas dataframe.

Get Closer To Your Dream of Becoming a Data Scientist with 70+ Solved End-to-End ML Projects

Step 1 - Import the library

import pandas as pd import random import matplotlib.pyplot as plt import seaborn as sns

We have imported various modules like pandas, random, matplotlib and seaborn which will be need for the dataset.

Step 2 - Setting up the Data

We have created a empty dataset and then by using random function we have created set of random data and stored in X and Y. We have used print function to print the dataset. df = pd.DataFrame() df['x'] = random.sample(range(1, 50), 25) df['y'] = random.sample(range(1, 100), 25) print(); print(df.head()) print(); print(df.tail())

 

Explore More Data Science and Machine Learning Projects for Practice. Fast-Track Your Career Transition with ProjectPro

Step 3 - Ploting different Plots

So we will be ploting different plots by using seaborn.

    • First we are ploting Scatterplot by passing the required parameters

sns.lmplot('x', 'y', data=df, fit_reg=False)

    • Now we are ploting a regression line which fits the data

sns.lmplot('x', 'y', data=df, fit_reg=True)

    • Now we are ploting a density plot for the data

sns.kdeplot(df.y); plt.show() sns.kdeplot(df.y, df.x); plt.show() sns.distplot(df.x); plt.show()

    • Now we are ploting a histogram for the data

plt.hist(df.x, alpha=.3) sns.rugplot(df.x) plt.show()

    • Now we are ploting a Boxplot for the data

sns.boxplot([df.y, df.x]) plt.show()

    • Now we are ploting a Violin Plot for the data

sns.violinplot([df.y, df.x]) plt.show()

    • Now we are ploting a Heatmap for the data

sns.heatmap([df.y, df.x], annot=False, fmt="d") plt.show()

    • Finally we are ploting a clustermap for the data

sns.clustermap(df) plt.show()

So the output comes as:

    x   y
0  15  22
1  36  61
2  39  71
3   3  46
4  38  85

     x   y
20   6  49
21  19  20
22   9  73
23  33  79
24  40  59

Join Millions of Satisfied Developers and Enterprises to Maximize Your Productivity and ROI with ProjectPro - Read ProjectPro Reviews Now!

Download Materials

What Users are saying..

profile image

Anand Kumpatla

Sr Data Scientist @ Doubleslash Software Solutions Pvt Ltd
linkedin profile url

ProjectPro is a unique platform and helps many people in the industry to solve real-life problems with a step-by-step walkthrough of projects. A platform with some fantastic resources to gain... Read More

Relevant Projects

Digit Recognition using CNN for MNIST Dataset in Python
In this deep learning project, you will build a convolutional neural network using MNIST dataset for handwritten digit recognition.

Build a Graph Based Recommendation System in Python-Part 2
In this Graph Based Recommender System Project, you will build a recommender system project for eCommerce platforms and learn to use FAISS for efficient similarity search.

Build Classification Algorithms for Digital Transformation[Banking]
Implement a machine learning approach using various classification techniques in Python to examine the digitalisation process of bank customers.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Build Multi Class Text Classification Models with RNN and LSTM
In this Deep Learning Project, you will use the customer complaints data about consumer financial products to build multi-class text classification models using RNN and LSTM.

Recommender System Machine Learning Project for Beginners-4
Collaborative Filtering Recommender System Project - Comparison of different model based and memory based methods to build recommendation system using collaborative filtering.

Avocado Machine Learning Project Python for Price Prediction
In this ML Project, you will use the Avocado dataset to build a machine learning model to predict the average price of avocado which is continuous in nature based on region and varieties of avocado.

Build Piecewise and Spline Regression Models in Python
In this Regression Project, you will learn how to build a piecewise and spline regression model from scratch in Python to predict the points scored by a sports team.

Llama2 Project for MetaData Generation using FAISS and RAGs
In this LLM Llama2 Project, you will automate metadata generation using Llama2, RAGs, and AWS to reduce manual efforts.

Build a Graph Based Recommendation System in Python -Part 1
Python Recommender Systems Project - Learn to build a graph based recommendation system in eCommerce to recommend products.