Get startedGet started for free

What percent of sales occurred at each store type?

While .groupby() is useful, you can calculate grouped summary statistics without it.

Walmart distinguishes three types of stores: "supercenters," "discount stores," and "neighborhood markets," encoded in this dataset as type "A," "B," and "C." In this exercise, you'll calculate the total sales made at each store type, without using .groupby(). You can then use these numbers to see what proportion of Walmart's total sales were made at each type.

sales is available and pandas is imported as pd.

This exercise is part of the course

Data Manipulation with pandas

View Course

Exercise instructions

  • Calculate the total weekly_sales over the whole dataset.
  • Subset for type "A" stores, and calculate their total weekly sales.
  • Do the same for type "B" and type "C" stores.
  • Combine the A/B/C results into a list, and divide by sales_all to get the proportion of sales by type.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Calc total weekly sales
sales_all = ____["____"].____()

# Subset for type A stores, calc total weekly sales
sales_A = ____[____["____"] == "____"]["____"].____()

# Subset for type B stores, calc total weekly sales
sales_B = ____

# Subset for type C stores, calc total weekly sales
sales_C = ____

# Get proportion for each type
sales_propn_by_type = [sales_A, ____, ____] / ____
print(sales_propn_by_type)
Edit and Run Code