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
549 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 (34 exercises) |
Topic ==> | Overview of Pandas (3 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.
This is quite a long exercise, but Wise Owl will hold your hand (wing?) for each step. The aim is just to give you an idea of what you can do wtih Pandas dataframes.
The workbook in the above folder contains a list from Wikipedia of the 30 most viewed videos on YouTube of all time (at the time of writing):
O world!
Start by creating a Python program called Brave new world.py which loads the data from this workbook into a Pandas dataframe. Here is the start of the command to prompt you:
import pandas as pd
# read the Excel workbook into a Pandas dataframe
videos = pd.read_excel(
Use the head function to show the top 5 rows only from the dataframe:
The first 5 rows.
Now set another variable called top_five to hold just the first 5 videos from the dataframe, but this time using slicing to get them. Now show a single series from this second dataframe giving the video names only, by picking out the item from the dictionary of columns using this syntax:
# show just the video names of the top 5
print(top_five["Video"])
This should give you this series:
The names of the first 5 videos.
Now set a third variable called sorted_videos to hold the videos sorted by publication date, with the most recently published coming first. Here is the syntax of how to do this:
# sort a dataframe by one or more columns
new_dataframe = original_dataframe.sort_values(
by=['Column name'],
ascending=[True or False]
)
Use iloc to print out just the last 2 columns of this sorted dataframe, using this syntax:
print(sorted_videos.iloc[slicing for rows,slicing for columns])
You should now see something like this:
We're showing all of the rows, but only the last two columns.
Phew! Save your program and close it down, and watch Baby Shark for a bit of light relief.
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 2024. All Rights Reserved.