Making Heatmap from Pandas Dataframe

Given a Pandas DataFrame, we have to make heatmap from it.
Submitted by Pranit Sharma, on June 22, 2022

Pandas is a special tool that allows us to perform complex manipulations of data effectively and efficiently. Inside pandas, we mostly deal with a dataset in the form of DataFrame. DataFrames are 2-dimensional data structures in pandas. DataFrames consist of rows, columns, and the data.

Data visualization is a process of representing the data in the form of graphs, plots, and other pictorial formats for better understanding of data and effective analysis of data.

Making Heatmap from Pandas Dataframe

To make a heatmap from pandas DataFrame, use seaborn.heatmap() method, it plots rectangular data as a color-encoded matrix. To use this function, you need to install seaborn library first. The seaborn library is a Python data visualization library that works with the matplotlib and provides a high-level interface for drawing attractive and informative statistical graphics.


To work with pandas, we need to import pandas package first, below is the syntax:

import pandas as pd

To use seaborn, use the following import statement:

import seaborn as sns

Let us understand with the help of an example,

Python program to make heatmap from pandas Dataframe

# Importing pandas package
import pandas as pd

# Importing seaborn as sns
import seaborn as sns

# Creating a dictionary
d = {

# Creating a DataFrame
df = pd.DataFrame(d)

# Creating heapmap
heap = sns.heatmap(df)

# Display heap


The output of the above program is:

Example: Making Heatmap from Pandas Dataframe

Python Pandas Programs »

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.