Search⌘ K

Solution Review: Exploring E-Commerce

Explore techniques to analyze e-commerce data through grouping, sorting, and filtering in Python. Understand how to identify top customers by orders and spending, discover leading countries by sales, track monthly order counts, and find the most popular products. This lesson prepares you to extract key insights from business data without programming experience.

1. Top 55 customers with the highest number of orders

Python 3.5
import pandas as pd
df = pd.read_csv('e_commerce.csv')
# solution
temp = 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 CustomerID and call size to retrieve the number of times each CustomerID appeared in the data in line 5.
  • Second, we sort the values in descending order using sort_values in line 6.
...