Home »
Python »
Python Programs
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.
To make a heatmap from pandas DataFrame, we need to install the seaborn library. We will use seaborn.heatmap() method to make a heatmap.
To work with pandas, we need to import pandas package first, below is the syntax:
import pandas as pd
Let us understand with the help of an example,
Python code 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 = {
'Ram_Marks':[87,88,82,79,77],
'Shyam_Marks':[97,78,80,89,74],
'Seeta_Marks':[50,28,72,69,57],
'Geeta_Marks':[78,88,28,97,77]
}
# Creating a DataFrame
df = pd.DataFrame(d)
# Creating heapmap
heap = sns.heatmap(df)
# Display heap
print(heap)
Output:
Python Pandas Programs »