Creating charts in Excel
Spreadsheets include a lot of tools to deal with data, including presenting the data in colorful charts. Let's see how to append a chart programmatically to an Excel spreadsheet.
Getting ready
We will use the openpyxl
module. We should install the module, adding it to our requirements.txt
file as follows:
$ echo "openpyxl==3.0.3" >> requirements.txt
$ pip install -r requirements.txt
We'll store it in the new file information about the movies with the most attendance. The data is extracted from here: http://www.mrob.com/pub/film-video/topadj.html.
How to do it...
- Import the
openpyxl
module and create a new Excel file:>>> import openpyxl >>> from openpyxl.chart import BarChart, Reference >>> xlsfile = openpyxl.Workbook()
- Add data about the number of attendees in this sheet from the source. Only the first three are added for simplicity:
>>...