Part 5. Pandas Data Visualization – Learn Cool Matplotlib And Seaborn Libraries!

Pandas Data Visualization
Share this post and Earn Free Points!

In this post we will dive into topic: Pandas Data Visualization. This part will teach you how to make various sorts of visualisations with Pandas and other popular libraries like Matplotlib and Seaborn. You will learn how to make line plots, scatter plots, bar plots, and other types of plots.

Introduction

Pandas Data Visualization

A well-liked Python" data manipulation toolkit called Pandas offers strong capabilities for working with structured data. One of Pandas’ main advantages is its simplicity in producing various visuals utilising well-liked visualisation libraries like Matplotlib and Seaborn.

To gain insights from data, visualisation is a crucial stage in the processing and analysis of data. With data in a Pandas DataFrame", line plots, scatter plots, bar graphs, and many other visualisations may be easily made using Pandas data visualisation. Pandas offers a versatile and user-friendly interface for producing high-quality visuals by utilising the capability of other visualisation libraries like Matplotlib and Seaborn.

By using this method, analysts and data scientists may quickly produce appealing and instructive visualisations that aid in data exploration, the recognition of links and patterns within the data, and the dissemination of their results. Users may extract useful insights from their data using Pandas data visualisation and base their decisions on those findings.

Pandas Data Visualization

In the following examples I have used the House Prices dataset from Kaggle site. You can download it here!

There you can find sample of the data from this dataset".

Part 5. Pandas Data Visualization - Learn Cooll Matplotlib And Seaborn Libraries!

1. Line Plot Of Housing Prices Over Time

Using the Pandas groupby() function to group the data by furnishing status and determine the median price for each status, this code displays a line plot showing the median dwelling price by furnishing status. The generated graphic illustrates how the median home price fluctuates depending on how furnished the home is.

import pandas as pd
import matplotlib.pyplot as plt

# Load the dataset
data = pd.read_csv('housing_prices.csv')

# Create a line plot of the median housing price over time
data.groupby('furnishingstatus')['price'].median().plot()
plt.xlabel('Furnishing Status')
plt.ylabel('Median Price')
plt.title('Median Housing Price by Furnishing Status')
plt.show()
Part 5. Pandas Data Visualization - Learn Cooll Matplotlib And Seaborn Libraries!
Median Housing Price by Furnishing Status

2. Scatter Plot Of Housing Prices vs Area

To illustrate the link between housing cost and location, this code generates a scatter plot using Seaborn. The resulting map demonstrates how the cost of a home rises with the size of the region.

import seaborn as sns

# Load the dataset
data = pd.read_csv('housing_prices.csv')

# Create a scatter plot of housing price vs. area
sns.scatterplot(x='area', y='price', data=data)
plt.xlabel('Area')
plt.ylabel('Price')
plt.title('Housing Price vs. Area')
plt.show()
Part 5. Pandas Data Visualization - Learn Cooll Matplotlib And Seaborn Libraries!
Scatter Plot Of Housing Prices vs Area

3. Bar Plot Of Housing Prices By Main Road

To display the median housing price for homes situated on mainroad in comparison to those situated off mainroad, this code builds a bar plot using Matplotlib. The generated graphic illustrates how the median home price fluctuates depending on where the house is located.

import matplotlib.pyplot as plt

# Load the dataset
data = pd.read_csv('housing_prices.csv')

# Create a bar plot of the median housing price by mainroad
data.groupby('mainroad')['price'].median().plot(kind='bar')
plt.xlabel('Mainroad')
plt.ylabel('Median Price')
plt.title('Median Housing Price by Mainroad')
plt.show()
Part 5. Pandas Data Visualization - Learn Cooll Matplotlib And Seaborn Libraries!
Bar Plot Of Housing Prices By Main Road

4. Bar Plot – Visualize The Number Of Houses With Air Conditioning vs Those Without Air Conditioning

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('housing_prices.csv')
ac_counts = df['airconditioning'].value_counts()
plt.bar(ac_counts.index, ac_counts.values)
plt.xlabel('Air Conditioning')
plt.ylabel('Number of Houses')
plt.title('Number of Houses with and without Air Conditioning')
plt.show()
Part 5. Pandas Data Visualization - Learn Cooll Matplotlib And Seaborn Libraries!
Visualize The Number Of Houses With Air Conditioning vs Those Without Air Conditioning

5. Line Plot – Visualize The Trend Of Average Price Per Bedroom

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('housing_prices.csv')
price_by_bedroom = df.groupby('bedrooms')['price'].mean()
plt.plot(price_by_bedroom.index, price_by_bedroom.values)
plt.xlabel('Bedrooms')
plt.ylabel('Average Price')
plt.title('Average Price per Bedroom')
plt.show()
Part 5. Pandas Data Visualization - Learn Cooll Matplotlib And Seaborn Libraries!
Line Plot – Visualize The Trend Of Average Price Per Bedroom

Summary

Overall, Pandas data visualisation is a crucial tool for any workflow involving the processing and analysis of data since it enables users to quickly produce a variety of representations and effectively share their results with others.

In this post you saw multiple Pandas visualization examples which should give you the strong basics when you will deal with more complex cases.

Could You Please Share This Post? 
I appreciate It And Thank YOU! :)
Have A Nice Day!

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?