Search⌘ K
AI Features

Challenge 1: pandas Essentials

Explore pandas essentials by working through practical exercises that involve displaying datasets, calculating statistics, counting professions by categories, and identifying loyal customers based on spending. This lesson helps you develop hands-on skills in data manipulation and analysis using Python's pandas library.

E-commerce purchases exercise

We have a dataset that contains fictional customer information for purchases made online and in physical stores. Assume the goal is to analyze this dataset to improve marketing strategies and understand the customer base.

The solution is given at the end of the exercise. There can be multiple solutions to every task.

Note: The following data file does not need to be loaded. The dataset is provided with the exercise questions.

A sample preview of the dataset is provided below:

Use the code segment below to read the file and create a DataFrame:

Python 3.5
# First thing first, import Pandas :)
import pandas as pd
cust = pd.read_csv('Cust_Purch_FakeData.csv')
print(cust)

Task 1: Display the head

To see what the data looks like, display the first five rows of the dataset.

Input

N/A

Output

Must return the first five rows of the DataFrame.

Python 3.5
import pandas as pd
def display_first_5_Rows():
cust = pd.read_csv('Cust_Purch_FakeData.csv')
#Your Code Here

Task 2: Min, max, and mean of ages

Return the max, min, and mean of the ages of customers in the dataset. To return all the values, store the records in a list like this: [min, max, mean]. Follow this pattern for test cases:

Input

N/A

Output

A list containing the minimum, maximum, and mean of the ages.

Sample output

[min,max,mean]

Python 3.5
def min_max_mean_of_ages():
# Your Code Here
return None

Task 3: Count of structural engineers

Calculate how many customers have the profession “Structural Engineer”.

Input

N/A

Output

Return an integer value of the number of “Structural Engineers” in our DataFrame.

Python 3.5
def number_of_structural_engineers():
# Your Code Here
return None

Task 4: Count of structural engineers based on their sex

Calculate how many of the customers who have the profession “Structural Engineer” are male.

Input

N/A

Output

Return an integer value of the number of “Structural Engineers” who are male in our DataFrame.

Python 3.5
def number_of_male_structural_engineers():
# Your Code Here
return None

Task 5: Loyal customers

The company wants to send a thank-you coupon to those who spent 100 CAD or more as a loyalty reward. Find out which customers spent 100 CAD or more, and return the list of their email addresses.

Use the 'price(CAD)' column to get the total CAD spent.

Input

N/A

Output

Return a list containing the emails of all the employees who have spent more than 100 CAD.

Sample output

['hav@jek.gs', 'get@jovu.ag', 'goh@tuwjaz.gd']

Python 3.5
def loyalCustomers():
# Your Code Here
return None