0% found this document useful (0 votes)
22 views7 pages

Data Visualization On Pandas - Jupyter Notebook

The document discusses different types of plots that can be created using Pandas including line plots, bar plots, histograms, scatter plots, box plots, and pie charts. It provides examples of code to generate each type of plot using a sample DataFrame containing sales data.

Uploaded by

classfunction9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

Data Visualization On Pandas - Jupyter Notebook

The document discusses different types of plots that can be created using Pandas including line plots, bar plots, histograms, scatter plots, box plots, and pie charts. It provides examples of code to generate each type of plot using a sample DataFrame containing sales data.

Uploaded by

classfunction9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

3/26/24, 12:59 PM data visualization on Pandas - Jupyter Notebook

# Data visualization in Pandas

# Pandas supports the following plot kinds:


NoteBook By Tariq Ahmed (WP:+923070996076)
1. line
2. bar
3. scatter
4. hist
5. box
6. pie
7. heatmap

In [17]: import pandas as pd

In [2]: with open('Diwali Sales Data.csv') as f:


print(f)

<_io.TextIOWrapper name='Diwali Sales Data.csv' mode='r' encoding='cp1252'>

In [3]: df=pd.read_csv('Diwali Sales Data.csv',encoding='cp1252')

Create Plots
1. Line plot: To plot a line plot, you need to have at least one numeric column in your
DataFrame.
2. Bar plot: The DataFrame must have at least one categorical column.
3. Histogram: in histogram need numeric column to plot.in histogram need at least one
numeric column to plot,The numeric column must be specified as the x parameter.
4. Scatter plot: A scatter plot can have two numeric columns or two object columns.
5. Box plot: The DataFrame must have at least one numeric column.,The numeric column
must be specified as the x parameter.
6. Pie chart: The DataFrame must have at least one numeric column.
7. Heatmap: A heatmap can have two numeric columns or two object columns.

1. Line plot:

localhost:8888/notebooks/Class EDA/data visualization on Pandas.ipynb#6.-Pie-chart 1/7


3/26/24, 12:59 PM data visualization on Pandas - Jupyter Notebook

In [4]: df.head(2)

Out[4]:
Age
User_ID Cust_name Product_ID Gender Age Marital_Status State Zon
Group

0 1002903 Sanskriti P00125942 F 26-35 28 0 Maharashtra Weste

1 1000732 Kartik P00110942 F 26-35 35 1 Andhra Pradesh Southe

In [5]: df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 11251 entries, 0 to 11250
Data columns (total 15 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 User_ID 11251 non-null int64
1 Cust_name 11251 non-null object
2 Product_ID 11251 non-null object
3 Gender 11251 non-null object
4 Age Group 11251 non-null object
5 Age 11251 non-null int64
6 Marital_Status 11251 non-null int64
7 State 11251 non-null object
8 Zone 11251 non-null object
9 Occupation 11251 non-null object
10 Product_Category 11251 non-null object
11 Orders 11251 non-null int64
12 Amount 11239 non-null float64
13 Status 0 non-null float64
14 unnamed1 0 non-null float64
dtypes: float64(3), int64(4), object(8)
memory usage: 1.3+ MB

localhost:8888/notebooks/Class EDA/data visualization on Pandas.ipynb#6.-Pie-chart 2/7


3/26/24, 12:59 PM data visualization on Pandas - Jupyter Notebook

In [6]: df.plot(x='Occupation', y='Amount', kind='line')


#To plot a line plot, you need to have at least one numeric column in your Data

2. Bar Plot

localhost:8888/notebooks/Class EDA/data visualization on Pandas.ipynb#6.-Pie-chart 3/7


3/26/24, 12:59 PM data visualization on Pandas - Jupyter Notebook

In [7]: df.plot(x='Occupation', y='Amount', kind='bar')


#The DataFrame must have at least one categorical column.

Out[7]: <Axes: xlabel='Occupation'>

3. Histogram

localhost:8888/notebooks/Class EDA/data visualization on Pandas.ipynb#6.-Pie-chart 4/7


3/26/24, 12:59 PM data visualization on Pandas - Jupyter Notebook

In [8]: df.plot(x='Age',kind='hist') # in histogram need at least one numeric column to


#The numeric column must be specified as the x parameter.

Out[8]: <Axes: ylabel='Frequency'>

4 Scatter plot

localhost:8888/notebooks/Class EDA/data visualization on Pandas.ipynb#6.-Pie-chart 5/7


3/26/24, 12:59 PM data visualization on Pandas - Jupyter Notebook

In [9]: df.plot(x='State', y='Occupation', kind='scatter')


#A scatter plot can have two numeric columns or two object columns.

Out[9]: <Axes: xlabel='State', ylabel='Occupation'>

5. Box plot:

localhost:8888/notebooks/Class EDA/data visualization on Pandas.ipynb#6.-Pie-chart 6/7


3/26/24, 12:59 PM data visualization on Pandas - Jupyter Notebook

In [10]: df.plot(x='Age', kind='box')



#The DataFrame must have at least one numeric column.,
#The numeric column must be specified as the x parameter.

# 6. Pie chart use seaborn

localhost:8888/notebooks/Class EDA/data visualization on Pandas.ipynb#6.-Pie-chart 7/7

You might also like