0% found this document useful (0 votes)
74 views

Data Visualization in Excel Using Python

This document discusses creating data visualizations in Excel using Python. It explains how to use the ExcelWriter module in Pandas to write data and visualizations directly to an Excel file. The code example loads diabetes dataset, creates objects in Excel, and generates different chart types including bar charts, scatter plots, line plots, and area charts. The visualizations are directly embedded in the Excel sheet.

Uploaded by

dung pham anh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Data Visualization in Excel Using Python

This document discusses creating data visualizations in Excel using Python. It explains how to use the ExcelWriter module in Pandas to write data and visualizations directly to an Excel file. The code example loads diabetes dataset, creates objects in Excel, and generates different chart types including bar charts, scatter plots, line plots, and area charts. The visualizations are directly embedded in the Excel sheet.

Uploaded by

dung pham anh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Data Visualization In Excel Using Python

towardsdatascience.com/data-visualization-in-excel-using-python-94feeacda2fc

August 25, 2021

This is your last free member-only story this month.

Sign up for Medium and get an extra one

Using ExcelWriter for Creating Visualizations in Excel by Python


Code

Source: By Author

Excel is widely used for data analysis and has a lot of functionalities for analyzing,
manipulating, visualizing, etc. Using excel should be one of the main skills required for a
Data Analyst, Product Analyst, and Business Analyst. It helps in understanding the data
and how we can use it for generating useful insights.

Python is also widely used for Data Analysis purposes and also overcomes the drawbacks
of Excel. With a little knowledge of Python, we can enhance our Data Analysis skills and
also generate more useful insights.

Combining both Excel and Python can be fruitful and makes Data Analysis more
interesting. ExcelWriter is used for performing different Excel operations using Python. It
provides a wide variety of functionalities like creating an Excel, writing data into an Excel
sheet, creating visualizations in Excel, etc.

In this article, we will explore ExcelWriter and create some visualizations using it.

Let’s get started…

Installing required libraries


Excelwriter is defined in Pandas so we don’t need to install it separately.

Importing required libraries


In this step, we will import all the libraries that are required for reading Excel and
creating visualizations in Excel using Python.

import pandas as pd
import numpy as np

1/3
Loading Dataset
For this article, we will the famous Diabetes dataset that can be downloaded from online
sources. Also, we will create an excel file using excel writer where we will create
visualizations.

df = pd.DataFrame(pd.read_csv("/content/test.csv"))
writer = pd.ExcelWriter('diabetes.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1', startrow=2)

Creating Visualization In Excel


In this step, we will create different types of visualization, write them to the excel file we
created and then save the visualization. Before creating the visualizations we will also
create objects for the writer to use for further manipulation.

The code given below will create the objects and different graphs that are Bar Chart,
Scatter Plot, Line Plot, and Area Chart.

book = writer.book
sheet = writer.sheets['Sheet1']# Title
bold = book.add_format({'bold': True, 'size': 24})
sheet.write('A1', 'Diabetes', bold)
format1 = book.add_format({'font_color': '#E93423'})
sheet.conditional_format('B4:E8', {'type': 'cell', 'criteria': '<=', 'value': 0,
'format': format1})# Bar Chart
chart = book.add_chart({'type': 'column'})
chart.add_series({'values': '=Sheet1!B4:B90', 'name': '=Sheet1!B3', 'categories':
'=Sheet1!$A$4:$A$8'})
chart.add_series({'values': '=Sheet1!C4:C90', 'name': '=Sheet1!C3'})
chart.add_series({'values': '=Sheet1!D4:D90', 'name': '=Sheet1!D3'})
chart.add_series({'values': '=Sheet1!E4:E90', 'name': '=Sheet1!E3'})
sheet.insert_chart('K2', chart)# Scatter Chart
chart = book.add_chart({'type': 'scatter'})
chart.add_series({'values': '=Sheet1!F4:F90', 'name': '=Sheet1!B3', 'categories':
'=Sheet1!$A$4:$A$8'})
sheet.insert_chart('K20', chart)# Line Chart
chart = book.add_chart({'type': 'line'})
chart.add_series({'values': '=Sheet1!F4:F90', 'name': '=Sheet1!B3', 'categories':
'=Sheet1!$A$4:$A$8'})
chart.add_series({'values': '=Sheet1!G4:G90', 'name': '=Sheet1!C3'})
chart.add_series({'values': '=Sheet1!H4:H90', 'name': '=Sheet1!D3'})
chart.add_series({'values': '=Sheet1!I4:I90', 'name': '=Sheet1!E3'})
sheet.insert_chart('S2', chart)# Area Chart
chart = book.add_chart({'type': 'area'})
chart.add_series({'values': '=Sheet1!A4:F90', 'name': '=Sheet1!B3', 'categories':
'=Sheet1!$A$4:$A$8'})
chart.add_series({'values': '=Sheet1!B4:G90', 'name': '=Sheet1!C3'})
chart.add_series({'values': '=Sheet1!H4:H90', 'name': '=Sheet1!D3'})
chart.add_series({'values': '=Sheet1!I4:I90', 'name': '=Sheet1!E3'})
sheet.insert_chart('S20', chart)writer.save()

Visualizations(Source: By Author)

2/3
Here you can clearly visualize different types of charts that we created using excel writer.
We created these visualizations directly in an Excel sheet so you need to open the excel to
visualize these graphs. Try this with different datasets, create different visualizations, and
let me know your comments in the response section.

This article is in collaboration with

Piyush Ingale
.

Before You Go
Thanks for reading! If you want to get in touch with me, feel free to reach me at
[email protected] or my LinkedIn Profile. You can view my Githubprofile for
different data science projects and packages tutorials. Also, feel free to explore my
profile and read different articles I have written related to Data Science.

3/3

You might also like