Solution Review: Exploring E-Commerce
This lesson provides solutions to the exercise on exploring E-Commerce Dataset in previous lesson.
1. Top customers with the highest number of orders
Press + to interact
Python 3.5
import pandas as pddf = pd.read_csv('e_commerce.csv')# solutiontemp = df.groupby('CustomerID').size()temp = temp.sort_values(ascending=False)temp = temp.iloc[:5]print(temp)
We do this task in three steps:
- First, we group our data with
CustomerIDand callsizeto retrieve the number of times eachCustomerIDappeared in the data in line 5. - Second, we sort the values in descending order using
sort_valuesin line 6.
Ask