-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Closed
Labels
ConditionalsE.g. where, mask, case_whenE.g. where, mask, case_whenDocsNeeds InfoClarification about behavior needed to assess issueClarification about behavior needed to assess issue
Description
Pandas version checks
- I have checked that the issue still exists on the latest versions of the docs on
mainhere
Location of the documentation
https://pandas.pydata.org/docs/dev/reference/api/pandas.Series.case_when.html
Documentation problem
The example provide is not intuitive.
Suggested fix for documentation
I found the example of pd.Series.case_when very non intuitive hence here is the updated example
Examples
--------
>>> # Real-world example: Updating product prices based on a dynamic pricing strategy
>>> current_prices = pd.Series([50, 75, 100, 120], name='current_prices')
>>> demand_forecast = pd.Series([100, 80, 50, 120], name='demand_forecast')
>>> # Conditions for price adjustments based on demand forecast
>>> conditions = [
... (demand_forecast > 90, current_prices * 1.2), # Increase by 20% for high demand
... (demand_forecast < 60, current_prices * 0.8), # Decrease by 20% for low demand
... (current_prices > 100, current_prices * 0.95) # Apply a 5% discount for high-priced items
... ]
>>> # Applying the dynamic pricing strategy
>>> updated_prices = current_prices.case_when(caselist=conditions)
>>> updated_prices
0 60.0
1 75.0
2 80.0
3 114.0
Name: current_prices, dtype: float64
Metadata
Metadata
Assignees
Labels
ConditionalsE.g. where, mask, case_whenE.g. where, mask, case_whenDocsNeeds InfoClarification about behavior needed to assess issueClarification about behavior needed to assess issue