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!

Software ==> Python  (25 exercises)
Version ==> Latest version
Topic ==> Overview of Pandas  (1 exercise)
Level ==> Average difficulty
Classroom ==> Python programming
Online ==> Python programming
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

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:

Poohsticks scores

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:

Reading excel

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:

Three 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:

Renamed columns

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:

Summary statistics

The minimum, maximum, median and average score and number of games played.

 

Close your program down!

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post