How to use seaborn to visualise a Pandas dataframe?

How to use seaborn to visualise a Pandas dataframe?

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.

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())

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); sns.kdeplot(df.y, df.x); sns.distplot(df.x);
  • Now we are ploting a histogram for the data
  • plt.hist(df.x, alpha=.3) sns.rugplot(df.x)
  • Now we are ploting a Boxplot for the data
  • sns.boxplot([df.y, df.x])
  • Now we are ploting a Violin Plot for the data
  • sns.violinplot([df.y, df.x])
  • Now we are ploting a Heatmap for the data
  • sns.heatmap([df.y, df.x], annot=False, fmt="d")
  • Finally we are ploting a clustermap for the data
  • sns.clustermap(df)
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

Download Materials

Relevant Projects

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Medical Image Segmentation Deep Learning Project
In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Abstractive Text Summarization using Transformers-BART Model
Deep Learning Project to implement an Abstractive Text Summarizer using Google's Transformers-BART Model to generate news article headlines.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Ola Bike Rides Request Demand Forecast
Given big data at taxi service (ride-hailing) i.e. OLA, you will learn multi-step time series forecasting and clustering with Mini-Batch K-means Algorithm on geospatial data to predict future ride requests for a particular region at a given time.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.