Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
485 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | Python (36 exercises) |
Topic ==> | Matplotlib (2 exercises) |
Level ==> | Relatively easy |
Subject ==> | Python training |
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
The Excel workbook in the above folder contains a list of the tallest buildings in the world (at the time of writing this exercise, at any rate):
Against each building is the city and country where it can be found.
The aim of this exercise is to create a chart showing the number of buildings by country:
No great surprise that China has by far the most tall buildings!
Read on for how to do this!
Start by reading the data into a Pandas dataframe, counting the number of buildings per country and turning the results into a NumPy array. Here's one way to do this:
# read Excel worksheet into dataframe (defaults to sheet 1)
buildings_table = pd.read_excel("c:/wiseowl/tallest buildings.xlsx")
# group by country and count buildings
country_counts = buildings_table["Country"].value_counts()
# turn first (index) column into a normal column
country_counts = country_counts.reset_index()
# change the column names
country_counts.columns = ["Country", "Number of buildings"]
# turn this into an array
country_data = country_counts.to_numpy()
As metnioned above, this is only one way to do this - there are many, many ways to skin a Panda in Python.
Now use barh to create a bar chart, adding a title and X and Y axis labels. Here are a couple of lines of code to remind you of how to proceed:
# create a chart
fig, ax = plt.subplots()
# plot this
ax.barh(country_data[:,0],country_data[:,1])
When you're happy that your chart is appearing OK, save and close your code file.
You can find other training resources for the subject of this exercise here:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2025. All Rights Reserved.