Pricing Optimization
Well, I guess the headline of this article already gives all of you a great hint on what I am going to discuss here.
So, in every business settings, I personally think that pricing is the top 3 most important factors in order to maximize our revenue.
If a product is priced too high then most likely customers will switch to competitors, and on the other hand If the price is too low then the company is losing Its revenue over time.
The above scenario is just one of the many problems available, hence the main question is
“How much price should we give on any given product ?”
And I am going to show you how we can use python and Its library statsmodel to develop and optimize our pricing model.
Get KDataInc’s stories in your inbox
Join Medium for free to get updates from this writer.
Guidelines :
- Data Preparation
- Developing Price Optimization
- Summary
1. Data Preparation
#Load CSV Data
revenue = pd.read_csv('/kaggle/input/netflix2020/NetflixsRevenue2018toQ2_2020.csv')
subscriber = pd.read_csv('/kaggle/input/netflix2020/NetflixSubscribersbyCountryfrom2018toQ2_2020.csv')#Convert Columns into Rows
revenue = pd.melt(revenue, id_vars = ['Area'], value_vars = revenue.columns[1:])
subscriber = pd.melt(subscriber, id_vars = ['Area'], value_vars = subscriber.columns[1:])#Rename Columns for Readability
subscriber = subscriber.rename(columns = {'value' : 'customers'})
revenue = revenue.rename(columns = {'value' : 'revenue'})df_merge = pd.merge(subscriber, revenue, on = ['Area','variable'], how = 'left')
df_merge#Generate Price Columns per Quarter per Area
df_merge['avg_price'] = round(df_merge['revenue']/df_merge['customers'],2)
df_merge.sort_values(by = 'avg_price')
Here are the summary from the above steps :
- Load the CSV Files
- Using pandas.melt to convert the Dataframes Columns into Rows
- Changing our columns name
- Merge both of the Revenue and Subscribers Data to generate a final summary table
- Finally, since we don’t have the pricing data, we can generate It by dividing revenue with total customers
After all those steps have been fulfilled, we can directly implement our optimization model to determine which price values provide the most optimal revenue per Area.
2. Developing Price Optimization
#Developing our Pricing Model
from statsmodels.formula.api import olslist_df = []
list_df_max = []
for a in df_merge['Area'].unique() :
df = df_merge[df_merge['Area'] == a]model = ols("customers~avg_price", data = df).fit()
price = [x for x in df['avg_price']]
revenue = []
for b in price :
demand = model.params[0] + (model.params[1]*b)
revenue.append(demand*b)
df_price = pd.DataFrame({'area' : a, 'price' : price, 'revenue' : revenue})
df_price_max = df_price[df_price['revenue'] == df_price['revenue'].max()]
list_df.append(df_price)
list_df_max.append(df_price_max)
df_optimize = pd.concat(list_df_max, ignore_index = True)
df_optimize
Here are the description for the above processes :
- From statsmodels.formula.api, we import ols ( Ordinary Least Squares ) as our main model
- Then, we generate two lists for storing our generated dataframe ( one for the complete pricing list, and the other one for storing the maximum revenue )
- Since every region/area has different economic factors, we would want to train our model separately based on the area ( Using For Loops based on Area )
- In every Iterations, we will generate a dataframe and store It into the empty list we generated above.
- For Maximum Revenue, we need to filter the dataframe based on MAX revenue per Area before storing It into the dataframe
- Finally, combine all dataframes from the list to generate our final summary table.
Summary
This is the final result from the above codes, and as we can see, each Area has different sets of price with different revenue generated.
For pricing, this can be expanded into more factors such as category, cost, or other factors that matters to your business.
And that’s the end of It, I hope you find this article helpful to kick off your journey in developing your own pricing model.
Also, I am very interested to hear from all of you If you have any inputs or suggestions on how to make a better pricing model.
As usual, thank you and see you guys on the next article !









