Python | Overview of Pandas exercise | Reading in a dataframe, renaming columns and showing stats
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.
You can learn how to do this exercise if you attend the course listed below!
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
The Excel workbook above contains the results to date of this year's Poohsticks tournament in the Hundred Acre Wood:
Tigger is leading, although Pooh Bear and Roo have only played two games each.
Import the Pandas module in a new program, then read this workbook into a Pandas dataframe and show information for this using the info method:
Set your dataframe variable to be the results of running the pd.read_excel method of the Pandas module.
Apply the sort_values method to your dataframe then pick out the first 3 rows using the head function to show the current 3 leaders:
The leaderboard as things stand.
Apply the rename method to your dataframe, passing in a dictionary of objects where the key is the old name of each column and the value is the new name, to get this:
The dataframe with its new column names.
Finally apply the agg function to your final dataframe, passing in a dictionary where the key to each item is the name of each integer column and the value is a list of statistical functions you want to apply, to get:
The minimum, maximum, median and average score and number of games played.
Close your program down!