A Python data analysis project comparing retail branch performance across the 5 largest provinces on Java Island, using pandas pivot tables, groupby aggregation, and resampling to track monthly trends in orders, customers, products, brands, and GMV.
Originally published on Rose Data Scientist.
A company needed to compare branch performance across cities — specifically the 5 largest provinces on Java Island (DKI Jakarta, Jawa Barat, Jawa Tengah, Jawa Timur, and Yogyakarta) — across five metrics, on a monthly basis:
- Order count (unique orders)
- Customer count (unique customers)
- Product count (unique products sold)
- Brand count (unique brands sold)
- GMV (Gross Merchandise Volume — total sales value)
The goal was to automate chart generation for each of these measurements, comparing all 5 provinces side by side.
Four quarterly CSV files of retail transaction data:
| Period | Source |
|---|---|
| Jan – Mar | retail_data_from_1_until_3_reduce.csv |
| Apr – Jun | retail_data_from_4_until_6_reduce.csv |
| Jul – Sep | retail_data_from_7_until_9_reduce.csv |
| Oct – Dec | retail_data_from_10_until_12_reduce.csv |
All hosted at https://storage.googleapis.com/dqlab-dataset/10%25_original_randomstate%3D42/
The full analysis, in branch_performance.py, follows these steps:
- Load & combine data — read all 4 quarterly CSVs and concatenate into one dataframe
- Data inspection — check shape, columns, info, and descriptive statistics
- Data cleaning — drop rows with negative prices or undefined order IDs; cast
order_idto int64 andorder_dateto datetime - Filter to Java's 5 largest provinces
- Group & aggregate — by
order_dateandprovince, computing unique order/customer/product/brand counts and summed GMV - Unstack — reshape so
order_dateis the row index andprovincebecomes columns, for easy per-metric comparison - Slice by measurement — isolate each metric (e.g. order count) across all provinces
- Resample monthly — compute the monthly average for each metric
- Visualize — loop through all 5 measurements and plot each as a line chart (all provinces overlaid) in a single multi-panel figure
Average daily order size was highest and consistently growing in DKI Jakarta, followed by Jawa Barat, with the remaining three provinces (Jawa Tengah, Jawa Timur, Yogyakarta) trending at roughly similar, lower levels.
- Combining multiple CSVs with
pd.concat() - Data validation and cleaning (
.loc[]filtering, dtype casting) groupby().agg()with multiple aggregation functionsunstack()for reshaping long-format data into wide comparison tablespd.IndexSlicefor slicing multi-level columns- Time-based
resample('M')for monthly aggregation - Looping over measurements to generate a multi-panel
matplotlibfigure automatically
See requirements.txt. Core libraries: pandas, matplotlib.
MIT