0% found this document useful (0 votes)
23 views50 pages

Data Visualization Techniques in Python

The document is a practical record for students at Pope John Paul II College of Education, specifically within the Department of Computer Science, focusing on data visualization techniques using Python and Power BI. It outlines various types of data visualization methods, their advantages and disadvantages, and provides a detailed overview of tools and libraries for creating visual representations of data. Additionally, it includes a structured table of contents and sections for practical exercises related to data visualization projects.

Uploaded by

harishish1801
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)
23 views50 pages

Data Visualization Techniques in Python

The document is a practical record for students at Pope John Paul II College of Education, specifically within the Department of Computer Science, focusing on data visualization techniques using Python and Power BI. It outlines various types of data visualization methods, their advantages and disadvantages, and provides a detailed overview of tools and libraries for creating visual representations of data. Additionally, it includes a structured table of contents and sections for practical exercises related to data visualization projects.

Uploaded by

harishish1801
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

POPE JOHN PAUL II COLLEGE OF EDUCATION

Reddiarpalayam, Pondicherry-605 010.

DEPARTMENT OF COMPUTER SCIENCE

PRACTICAL RECORD

Name :…………………………………………………………………….

Registration No :…………………………………………………………………….

Semester :…………………………………………………………………….

Subject :…………………………………………………………………….
POPE JOHN PAUL II COLLEGE OF EDUCATION
Reddiarpalayam, Pondicherry-605 010.

DEPARTMENT OF COMPUTER SCIENCE

BONAFIDE CERTIFICATE

Certified that this is a bonafide record of practical work done by

Mr./Miss/Mrs.………………………………………………………………………… a student of

…….…………………….…………………………..Semester of B.C.A., in the Subject

………………………………………………………………………. Project/Laboratory during the

period ……………………to ……………………….

Head of the Department Staff-in-Charge

Submitted for the University Examination held on………………………………….........

University Registration No. ………………………………………………………………

External Examiner Internal Examiner


TABLE OF CONTENTS

[Link] DATE TITLE PAGE TEACHER’S


NO SIGN
1. DATA VISUALIZATION
INTRODUCTION
DATA VISUALIZATION USING
2. PYTHON

3. 4/8/2025 LINE CHART USING PYTHON

4. 11/8/2025 BAR CHART USING PYTHON


5. 18/8/2025 PIE CHART USING PYTHON

6. 25/8/2025 SCATTER PLOT USING PYTHON

7. 1/9/2025 AREA CHART USING PYTHON

8. 8/9/2025 HISTOGRAM USING PYTHON

9. DATA VISUALIZATION USING


POWER BI

10. 15/9/2025 SALES USING POWER BI

11. 22/9/2025 YEAR TO DATE SALES USING POWER


BI

12. 29/9/2025 CONDITIONAL FORMATTING RULE


USING POWER BI
13. 6/10/2025 DYNAMIC TOP N SALES REPORT
USING POWER BI

14. 13/10/2025 CUSTOMER RETENTION ANALYSIS


USING POWER BI
1

Data visualization
Data visualization is the process of creating graphical representations of information. This process helps
the presenter communicate data in a way that’s easy for the viewer to interpret and draw conclusions.

Data visualization involves presenting data in graphical or pictorial form which makes the information
easy to understand. It helps to explain facts and determine courses of action.

The primary goal of data visualization is to make data more accessible and easier to interpret,
allowing users to identify patterns, trends, and outliers quickly.

Visualization of data not only simplifies complex information but also enhances decision-making
processes.

Types of Data Visualization Techniques

1. BarCharts: Ideal for comparing categorical data or displaying frequencies, bar charts offer a clear visual
representation of values.

2. Line Charts: Perfect for illustrating trends over time, line charts connect data points to reveal patterns
and fluctuations.

3. Pie Charts: Efficient for displaying parts of a whole, pie charts offer a simple way to understand
proportions and percentages.

4. Scatter Plots: Showcase relationships between two variables, identifying patterns and outliers through
scattered data points.

5. Histograms: Depict the distribution of a continuous variable, providing insights into the underlying data
patterns.

6. Heatmaps: Visualize complex data sets through color-coding, emphasizing variations and correlations in
a matrix.

7. Box Plots: Unveil statistical summaries such as median, quartiles, and outliers, aiding in data distribution
analysis.

8. Area Charts: Similar to line charts but with the area under the line filled, these charts accentuate
cumulative data patterns.

9. Bubble Charts: Enhance scatter plots by introducing a third dimension through varying bubble sizes,
revealing additional insights.
2

10. Treemaps: Efficiently represent hierarchical data structures, breaking down categories into nested
rectangles.

11. Violin Plots: Violin plots combine aspects of box plots and kernel density plots, providing a detailed
representation of the distribution of data.

12. Word Clouds: Word clouds are visual representations of text data where words are sized based on their
frequency.

13. 3D Surface Plots: 3D surface plots visualize three-dimensional data, illustrating how a response variable
changes in relation to two predictor variables.

14. Network Graphs: Network graphs represent relationships between entities using nodes and edges. They
are useful for visualizing connections in complex systems, such as social networks, transportation
networks, or organizational structures.

15. Sankey Diagrams: Sankey diagrams visualize flow and quantity relationships between multiple entities.
Often used in process engineering or energy flow analysis.

Advantages of Data Visualization:

• EnhancedComparison: Visualizing performances of two elements or scenarios streamlines analysis,


saving time compared to traditional data examination.

• Improved Methodology: Representing data graphically offers a superior understanding of situations,


exemplified by tools like Google Trends illustrating industry trends in graphical forms.

• Efficient Data Sharing: Visual data presentation facilitates effective communication, making
information more digestible and engaging compared to sharing raw data.

• Sales Analysis: Data visualization aids sales professionals in comprehending product sales trends,
identifying influencing factors through tools like heat maps, and understanding customer types, geography
impacts, and repeat customer behaviors.

• Identifying Event Relations: Discovering correlations between events helps businesses understand
external factors affecting their performance, such as online sales surges during festive seasons.

• Exploring Opportunities and Trends: Data visualization empowers business leaders to uncover patterns
and opportunities within vast datasets, enabling a deeper understanding of customer behaviors and insights
into emerging business trends.
3

Disadvantages of Data Visualization:

• Can be time-consuming: Creating visualizations can be a time-consuming process, especially when


dealing with large and complex datasets.

• Can be misleading: While data visualization can help identify patterns and relationships in data, it can
also be misleading if not done correctly.

• Can be difficult to interpret: Some types of visualizations, such as those that involve 3D or interactive
elements, can be difficult to interpret and understand.

• May not be suitable for all types of data: Certain types of data, such as text or audio data, may not lend
themselves well to visualization

• May not be accessible to all users: Some users may have visual impairments or other disabilities that
make it difficult or impossible for them to interpret visualizations

Data Visualization Tools

A data visualization tool is a form of software that’s designed to visualize data.

• Microsoft Excel (and Power BI)


Power BI is an excellent alternative. Built specifically as a data analytics and visualization tool,
Power BI can import data from various sources and output visualizations in a range of formats.

• Google Charts
For professionals inte
rested in creating interactive data visualizations destined to live on the internet, Google Charts is
a popular free option.

• Tableau
Tableau is one of the most popular data visualization tools on the market for two main reasons: It’s
relatively easy to use and incredibly powerful. The software can integrate with hundreds of sources to
import data and output dozens of visualization types—from charts to maps and more.

• Zoho Analytics
Zoho Analytics is a data visualization tool specifically designed for professionals looking to
visualize business intelligence.
4

• Datawrapper
Datawrapper is a tool that, like Google Charts, is used to generate charts, maps, and other graphics
for use online.

• R Programming Language
R is a language that is designed for statistical computing, graphical data analysis, and scientific research.
It is usually preferred for data visualization as it offers flexibility and minimum required coding through
its packages.

• Python Language
Python offers several plotting libraries, namely Matplotlib, Seaborn and many other such data
visualization packages with different features for creating informative, customized, and appealing plots
to present data in the most simple and effective way.
5

Data Visualization with Python


Python provides various libraries that come with different features for visualizing data. Matplotlib and seaborn
libraries come with different features and can support various types of graphs.

• Matplotlib
• Seaborn

Matplotlib
➢ Matplotlib is an easy-to-use, low-level data visualization library that is built on NumPy arrays. It consists

of various plots like scatter plot, line plot, histogram, etc.


➢ Matplotlib provides a lot of flexibility.
➢ Matplotlib is open source and we can use it freely.
➢ Matplotlib is mostly written in python, a few segments are written in C, Objective-C and Javascript for

Platform compatibility.
➢ Matplotlib is a python library which provides many interfaces and function to present data in 2D graphics.
We can say, Matplotlib is a high quality plotting library of Python.
➢ Matplotlib library offers many different collections of sub modules; Pyplot is one such sub module.
➢ Pyplot is a collection of methods within Matplotlib library which allows user to construct 2D plots easily.

Most of the Matplotlib utilities lies under the pyplot submodule, and are usually imported under the plt alias:

import [Link] as plt

1. Line Chart or Line Graph

Line graph is a simple graph that shows the result in the form of lines. To create a line graph we
need x and y coordinates. For example-

[Link](x, y, ‘colorname’)

The plot() function is used to draw points (markers) in a diagram. By default, the plot() function draws a
line from point to point. The function takes parameters for specifying points in the diagram. Parameter 1 is
an array containing the points on the x-axis. Parameter 2 is an array containing the points on the y-axis.
6
7
Markers

The keyword argument marker can be used to emphasize each point with a specified marker.
'o' Circle
'*' Star
'.' Point
',' Pixel
'x' X
'X' X (filled)
'+' Plus
'P' Plus (filled)
's' Square
'D' Diamond
'|' Vline
'_' Hline

The shortcut string notation parameter can be used to specify the marker. This parameter is also calledfmt, and
is written with this syntax:

marker|line|color

• The line value can be one of the following

'-' Solid line


':' Dotted line
'--' Dashed line
'-.' Dashed/dotted linee one of the following

• The color value can be one of the following


'r' Red
'g' Green
'b' Blue
'c' Cyan
'm' Magenta
'y' Yellow
'k' Black
'w' White
8
• The keyword argument markersize or ms to set the size of the markers
• Use both the mec and mfc arguments to color the entire marker

Changing line color and line width and line style :


9

2. Bar Chart

➢ With Pyplot, the bar() function can be used to draw bar graphs.
➢ The categories and their values represented by the first and second argument as arrays.

➢ The bar() function take the keyword argument color to set the color of the bars
➢ The bar() takes the keyword argument width to set the width of the bars:
10
11
3. Histogram

Histogram shows distribution of values. Histogram is similar to bar graph but it is


useful to show values grouped in bins or intervals.
12
4. Pie Chart
A piechart shows a circle that is divided into sectors and each sector represents a proportion
of the whole.

• Sometimes we want to emphasize on one or more slice and show them little
pulled out. This feature is called explode in pie chart.

• If we want to explode or stand out 2 nd and 3 rd slice out of 5 slices to 0.2 and 0.3
unit respectively , explode will be [0,0.2,0.3,0,0]. The value of explode vary from
0.1 to 1 to show that how much a slice will come out of pie chart.
13

5. Scatter Plot

A scatter plot is a type of plot that shows the data as a collection of points in the form of dots,
and shows the relationship between two variables - one plotted along the x- axis and the other
plotted along y-axis.

Syntax-
Scatter(x, y, color, marker)

Marker- is a symbol (style) for representing data point. Following is a list of valid
marker style-

Marker Description
‘s’ Square Marker
‘o’ Circle Marker
‘d’ Diamond Marker
‘x’ Cross Marker
‘+’ Plus Marker
‘^’ Triangle down
14
What is Power BI?

Power BI is a free windows application that lets you connect to data, transform
data it, and create interactive visual reports. It’s part of the Power BI suite, which
also includes the power BI service (online) where you can publish and share your
reports.

With Power BI you can:

 Import data from excel, databases, web sources, and more


 Clean and shape your data using power query
 Build visual charts, maps, and tables
 Publish your reports to the Power BI service for sharing

Components of Power BI:

1) Ribbon - the top ribbon contains most of the controls and options
needed for building the report.
2) Views – this is made up of the report view, the data view, and the
model view.
3) Canvas – this is the main design area where visualizations and other
elements are added.
4) Page selector – for navigation to other pages in the report.
5) Filters – fields can be added here to filter the data.
6) Visualizations – this contain the list of available visualizations.
7) Fields – this section contains the tables and fields that are available in
the data model.
Data visualization in Power BI:

The Visualizations pane in Power BI Desktop contains a set of standard visuals


that can be used directly in your reports. Common built-in visuals include:
 Bar and column charts: Use horizontal bars (bar chart) or vertical columns
(column chart) to compare values across different categories. Variations
include clustered and stacked versions

 Line and area charts: Display trends over a continuous period, like time.
Area charts are similar but fill the space below the line to emphasize volume.
 Pie and donut charts: Show the proportions of a total, ideal for a small
number of categories. Donut charts have a hole in the center that can display
a key metric.

 KPI and gauge charts: Present a single value and measure its performance
against a defined target or goal. Gauges look like speedometers.
 Maps: Visualize geographically related data. You can use bubble maps to
show value by bubble size or filled maps to shade entire regions based on a
metric.

 Tables and matrices: Display data in a tabular format. A matrix is similar to


a pivot table in Excel, allowing you to summarize data by rows and columns.
 Cards: Show a single number, highlighting important figures and key
performance indicators (KPIs).

 Funnel charts: Illustrate a sequential process, like a sales pipeline, showing


how values decrease at each stage.

 Tree maps: Display hierarchical data as a set of nested rectangles, where the
size and color of each rectangle represent different values.
 Scatter and bubble charts: Analyze the relationship between two (scatter)
or three (bubble) different measures.
EX NO: 07 SALES SUMMARY
DATE:

AIM:-

To create a measures for total sales and profit and design a cluster column chart
to visualize sales by region.

TASKS:-

1. Load the dataset into Power BI.


2. Create a measures to calculate TOTAL SALES.
3. Create a measure to calculate PROFIT.
4. Create a cluster column chart to show SALES BY REGION.

DATASET:-

PROCEDURE: -

STEP-1: Load the dataset into power BI.


Go to the Home tab>Click on get Data>and select Text/CSV.
STEP-2: After selecting the file, you can see the data preview. Click on load.
STEP-3: Create a measure to calculate total profit and total sales.
 Right-click on the dataset and select “NEW MEASURE”.
 TOTAL SALES=SUM(SALES[SALES])
 PROFIT=SUM(SALES[SALES])-SUM(SALES[COST])
 Now add two card visual to the report page and drag both measures into
the card visuals.
STEP-4: Create a cluster column chart to show SALES BY REGION.
Add a clustered column chart to the report page, then drag the REGION
column to the X-axis and the TOTAL SALES measure to Y-axis.

OUTPUT:-
EX NO: 08 YEAR-TO-DATE SALES
DATE:

AIM:-

To create a measures for year –to-date(YTD) sales, and visualizing the results
with a line chart to track sales performance throughout the year.

TASKS:-

1. Load the dataset into power BI.


2. Add a DATE TABLE to the model.
3. Create a relationship between both tables.
4. Create a measure to calculate Year-to-Date Sales.
5. Create a line chart to display the YDT sales.

DATASET:-

PROCEDURE:-

STEP-1: Load the dataset into Power BI.


Go to the home tab> Click on get data>and select Text/CSV.
STEP-2: After selecting the file, you can see the data preview. Click on load.
STEP-3: Add a DATA TABLE to the model.
 Go to the Modeling tab>Click on New table.
 Write the DAX code below to create a date table
 Based on the minimum or maximum date from ‘PBI-2-SALES’,create the
date table.
 CALENDER=CALENDER(MIN(‘PBI-2-
SALES’[DATE]),MAX(‘PBI-2-SALES’[DATE]))
STEP-4: Create a relationship between both tables.
Go to the Model view>,and create a relationship between both tables.
STEP-5: Create a line chart to display the YDT sales.
 Right –click on the dataset and select “NEW MEASURES”.
 YDTSALES=CALCULATE(SUM(‘PBI-2-
SALES’[SALESAMOUNT]),DATESYTD(‘CALENDER’[DATE]))
 After that, add a line chart to the report page. Drag the year and month
columns from the calendar dataset to the x-axis of the chart, and drag the
YTD sales measures from the PBI-2-SALES dataset to the y-axis.

OUTPUT:-
EX NO: 09 CONDITIONAL FORMATTING RULE
DATE:

AIM:-

To create and display the rules in a table for easy visual analysis.

TASKS:-

1. Create a rule to highlight employees who scored above 80 in green and other in red.
2. Display the data in a table with conditional formatting.

DATASET:-

PROCEDURE:-

STEP-1: Create a rule to highlight employee who scored above 80 in green and others in
red:
 For this task, we will first add a calculated column for performance status.
If the employee’s score is greater than 80, we will show high, otherwise
will show low.
 Right-click on the dataset name and select ‘NEW COLUMN’.
 After that, write the DAX code below and click on the commit icon.
 PERFORMANCE STATUS= IF(EMPLOYEE[PERFORMANCE]
>80, “HIGH”, “LOW”).
STEP-2: Display the data in a table with conditional formatting:
 Add a table visual with the Employee Name and Performance Score
columns on the report page.
 After that, right-click on the Performance Score column, go to
Conditional Formatting, and select Font Color.
 Select Performance Status column from your dataset.
 In the first rule, provide the text 'High' and choose green as the color.
Then, click on '+New Rule' to add another rule for 'Low,' choose red as
the color, and click the 'OK' button.
 the result: employees who scored above 80 are highlighted in green, while
others are highlighted in red.

OUTPUT:-
EX NO: 10 DYNAMIC TOP N SALES REPORT
DATE:

AIM:-

To create a dynamic Top N sales report in Power BI.

TASKS:-

1. Load the dataset into Power BI.


2. Create a slicer for users to select Top N Products.
3. Create a measure for Top N.
4. Show the top N products in a table with their sales amount.

PROCEDURE:-

STEP-1: Load the dataset into Power BI:


 Go to the Home tab > Click on Get Data > and select Text/CSV.
 After selecting the file, you can see the data preview. Click on Load.
STEP-2: Create a slicer for users to select Top N Products:
 To achieve this, we will create a numeric range parameter.
 Go to the Modeling tab and select the Numeric Range from the New Parameter
dropdown.
 Name: Provide the name to Parameter: Select N
 Minimum: Set to 1. Define the minimum value for the slicer parameter.
 Increment: Set to 1. Specify the increment value, which will increase the range
by 1.
 Maximum: Set to 10. The slicer value can go up to a range of 10.
 Default: Set to 1.
 After that, click on the Create button.
 A numeric range parameter has been created for the Select N slicer.
STEP-3: Create a measure for Top N:
 Now, create two measures: Total Sales and Top N Sales.
 Right-click on the Sales dataset and select “New Measure.”
 TOTAL SALES = SUM(SALES[SALES])COPY
 TOP N SALES =IF(RANKX(ALL(SALES[PRODUCT]), [TOTAL
SALES]) <='SELECT N'[SELECT N VALUE],[TOTAL
SALES],BLANK()).
STEP-4: Show the top N products in a table with their sales amount:
 Add a table visual with the Product and Top N Sales measure. To check the
result, adjust the slicer value to filter the Top N records in the table visual.

OUTPUT:-
EX NO: 11 CUSTOMER RENTENTION ANALYSIS
DATE:

AIM: -

To create and display analysis of customer retention by categorizing customers as New


or Returning based on their purchase history.

TASKS: -

1. Load the dataset into Power BI and ensure relationships are established.
2. Create the following calculated columns and measures:
 Calculated Columns:
Add a column to classify customers as New or Returning based on their
transaction history.
 Measures:
Calculate the Total Revenue by Customer Type.
Calculate the Retention Rate as the percentage of returning customers.
3. Create the following visuals:
 A clustered column chart to compare Total Revenue for New vs. returning
customers.
 A card visual to display the Retention Rate (%).
 Add a line chart to display total revenue by monthly trends.

DATASET:-

Customer dataset:-
Transaction dataset: -

PROCEDURE:-

STEP-1: Load the customer dataset into Power BI.


STEP-2: Load the transaction dataset into Power BI.
STEP-3: Date Table
 Write the DAX code below to create a Date Table. Based on the minimum or
maximum date from Transactions, we will create the Date Table.
 Go to the Modeling tab > Click on New Table.
 DATE = CALENDAR(MIN(TRANSACTIONS[DATE]),
MAX(TRANSACTIONS[DATE]))
STEP-4: Create a relationship between all tables:
 Go to the Model View> and create a relationship between all tables.
 Customers(CustomerID) > Transactions(CustomerID).
 Transactions(Date)> Date(Date).
STEP-5: Create the following calculated columns and measures:
 Add a column to classify customers as New or Returning based on their
transaction history.
 Right-click on the Transactions dataset and select New Column. And write
the DAX code below.
 CUSTOMER TYPE =
IF(
CALCULATE(
COUNTROWS(TRANSACTIONS),
FILTER(ALL(TRANSACTIONS),
TRANSACTIONS[CUSTOMERID] =
EARLIER(TRANSACTIONS[CUSTOMERID]) &&
TRANSACTIONS[DATE] < EARLIER(TRANSACTIONS[DATE]) ) )
> 0,"RETURNING","NEW")
STEP-6: Explanation of the DAX Code:
 The formula checks whether the customer has any prior transactions in the
dataset.
 EARLIER(Transactions[Date]) references the current row’s date to
compare it with earlier transactions for the same customer.
 If a prior transaction exists, the customer is classified as “Returning”,
otherwise, they are classified as “New”.
STEP-7: Now, create two measures: Total Revenue and Retention Rate:
 Right-click on the Transactions dataset and select New Measure. And write
the DAX code below.
 TOTAL REVENUE = SUM(TRANSACTIONS[REVENUE])
 RETENTION RATE =
DIVIDE(
CALCULATE(
DISTINCTCOUNT(TRANSACTIONS[CUSTOMERID]),
TRANSACTIONS[CUSTOMER TYPE] = "RETURNING"),
DISTINCTCOUNT(TRANSACTIONS[CUSTOMERID]),0)
STEP-8: Create the following visuals:
 A clustered column chart to compare Total Revenue for New vs. Returning
customers.
Now, add a Clustered Column Chart to the report page. Set the X-
axis to the Customer Type calculated column and the Y-axis to the Total
Revenue DAX measure. Refer to the screenshot below for reference.
 Now add a card visual to display the Retention Rate (%):
Add a card visual to the report page and add the Retention Rate
measure. After that, select the measure, go to the Measure Tools tab, select
Percentage under the Format section, and set the Decimal Places to 0.
 Add a line chart to display total revenue by monthly trends:
Add a line chart to the report page and place the Year and Month
from the Date table on the X-axis, and the Total Revenue measure on the Y-
axis.
OUTPUT:-

You might also like