salesanalyzer_mds.segment_revenue_share

Functions

segment_revenue_share(→ pandas.DataFrame)

Segments products into three categories—cheap, medium, and expensive—

Module Contents

salesanalyzer_mds.segment_revenue_share.segment_revenue_share(sales_data: pandas.DataFrame, price_col: str = 'UnitPrice', quantity_col: str = 'Quantity', price_thresholds: tuple = None) pandas.DataFrame[source]

Segments products into three categories—cheap, medium, and expensive— based on price and calculates their respective share in total revenue.

Parameters:

sales_datapd.DataFrame

DataFrame containing historical sales data.

price_colstr

Column containing product prices. Default is ‘UnitPrice’.

quantity_colstr

Column containing quantities sold. Default is ‘Quantity’.

price_thresholdstuple, optional

User-defined price thresholds (cheap_threshold, expensive_threshold). If None, quantiles (0.33, 0.67) are used.

Returns:

pd.DataFrame

A DataFrame showing the total revenue share for each price segment: ‘cheap’, ‘medium’, ‘expensive’.

Raises:

ValueError:

If the input DataFrame is empty or specified columns contain missing data.

KeyError:

If any of the specified columns are missing in the DataFrame.

TypeError:

If any of the columns contain invalid data types.