Question: import pandas as pd import numpy as np # Load the data file _ path = ' C: / Users / ASUS / Desktop /

import pandas as pd
import numpy as np
# Load the data
file_path ='C:/Users/ASUS/Desktop/PART 1/mugs-preference-parameters-full.csv'
data = pd.read_csv(file_path)
# Define the product attributes for the proposed candidate
candidate ={
'price': 30,
'time_insulated': 1,
'capacity': 20,
'cleanability': 'Easy',
'containment': 'Leak Resistant', # This corresponds to pCnLk
'brand': 'C'
}
# Define the cost structure
cost_structure ={
'time_insulated': {0.5: 0.5,1: 1,3: 3},
'capacity': {12: 1.00,20: 2.6,32: 2.8},
'cleanability': {'Difficult': 1, 'Fair': 2.2, 'Easy': 3.0},
'containment': {'Slosh Resistant': 0.5, 'Spill Resistant': 0.8, 'Leak Resistant': 1}
}
# Calculate the cost of the proposed candidate
candidate_cost =(cost_structure['time_insulated'][candidate['time_insulated']]+
cost_structure['capacity'][candidate['capacity']]+
cost_structure['cleanability'][candidate['cleanability']]+
cost_structure['containment'][candidate['containment']])
# Define competitors
competitor_1={
'price': 30,
'time_insulated': 3,
'capacity': 20,
'cleanability': 'Easy',
'containment': 'Leak Resistant', # This corresponds to pCnLk
'brand': 'A'
}
competitor_2={
'price': 10,
'time_insulated': 1,
'capacity': 20,
'cleanability': 'Fair',
'containment': 'Spill Resistant', # This corresponds to pCnSp
'brand': 'B'
}
# Define utility calculation function
def calculate_utility(row, product):
utility =0
# Check if columns exist before accessing them
price_key = f'pPr{product["price"]}'
if price_key in row:
utility += row[price_key]* row.get('IPr',0)
time_key = f'pIn{product["time_insulated"]}'
if time_key in row:
utility += row[time_key]* row.get('Iin',0)
capacity_key = f'pCp{product["capacity"]}'
if capacity_key in row:
utility += row[capacity_key]* row.get('ICp',0)
cleanability_key = f'pCl{product["cleanability"][0]}'
if cleanability_key in row:
utility += row[cleanability_key]* row.get('ICl',0)
containment_key = product['containment'].replace("","")
containment_key = f'pCn{containment_key}' # Ensure it matches the column name
if containment_key in row:
utility += row[containment_key]* row.get('Icn',0)
brand_key = f'pBr{product["brand"]}'
if brand_key in row:
utility += row[brand_key]* row.get('IBr',0)
return utility
# Calculate utilities
data['utility_candidate']= data.apply(calculate_utility, product=candidate, axis=1)
data['utility_competitor_1']= data.apply(calculate_utility, product=competitor_1, axis=1)
data['utility_competitor_2']= data.apply(calculate_utility, product=competitor_2, axis=1)
# Calculate logit-adjusted probabilities
data['exp_utility_candidate']= np.exp(data['utility_candidate'])
data['exp_utility_competitor_1']= np.exp(data['utility_competitor_1'])
data['exp_utility_competitor_2']= np.exp(data['utility_competitor_2'])
data['prob_candidate']= data['exp_utility_candidate']/(
data['exp_utility_candidate']+ data['exp_utility_competitor_1']+ data['exp_utility_competitor_2']
)
# Calculate the average market share
market_share_candidate = data['prob_candidate'].mean()
# Calculate margin and expected profit per person
price_candidate = candidate['price']
margin_candidate = price_candidate - candidate_cost
expected_profit_per_person = market_share_candidate * margin_candidate
# Output the results
print(f"Market Share of Candidate: {market_share_candidate}")
print(f"Margin of Candidate: {margin_candidate}")
print(f"Expected Profit per Person: {expected_profit_per_person}")
# Check if expected profit per person is between 4 and 4.5
if 4<= expected_profit_per_person <=4.5:
print("The expected profit per person is between 4 and 4.5.")
else:
print("The expected profit per person is not between 4 and 4.5.")
Please check the code and calculation. I need the expected profit per person is to be 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!