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.
Table of Contents
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".
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()
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()
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()
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()
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()
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!
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?