Data grouping partitions dataframe rows by a shared value so each group can be processed separately. In a dashboard, filtering may leave many product, gender, and state rows for each day, while the chart needs one total per day. Pandas groupby performs that reduction across the selected dimensions. section 6.5.1 section 6.6
Aggregate daily sales
With a dataframe named df, group rows by Day, sum Sales within each group, and restore Day as a regular column: grouped = df.groupby('Day') data = grouped.apply( lambda df: df['Sales'].sum(), include_groups=False ).reset_index() For two CA rows on 2024-08-01—1500 and 1300—the result contains one row for that date with Sales equal to 2800. The grouped object represents the rows belonging to each day. apply runs the function separately for every group; include_groups=False prevents the function from operating on the group labels, and reset_index converts the resulting Day index back into a column. section 6.5.1
A reusable helper can apply a configured metric and rename the result columns to Day and Value. That grouped result can then feed a Plotly line chart displayed in Streamlit, allowing the same dashboard pattern to show several metrics.





