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

Relevant Projects

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

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.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.