- def get_prices(type):
- if type == 'A':
- return 1000, 400
- if type == 'B':
- return 800, 350
- if type == 'C':
- return 600, 350
- if type == 'D':
- return 550, 150
- if type == 'E':
- return 500, 150
- if type == 'F':
- return 450, 150
- def profit_from_client(row):
- room_price, service_price = get_prices(row['reserved_room_type'])
- if row['arrival_date_month'] == 'December' or row['arrival_date_month'] == 'January' or row['arrival_date_month'] == 'February':
- n = 1
- elif row['arrival_date_month'] == 'June' or row['arrival_date_month'] == 'July' or row['arrival_date_month'] == 'August':
- n = 1.4
- else:
- n = 1.2
- if row['is_canceled'] == 1:
- return -(room_price * n + service_price)
- else:
- return room_price * n - service_price * (1 + row['total_nights'] // 2)
- df_train['profit_from_client'] = df_train.apply(profit_from_client, axis=1)
- print('Прибыль для обучающей выборки:', df_train['profit_from_client'].sum())
- df_test['profit_from_client'] = df_test.apply(profit_from_client, axis=1)
- print('Прибыль за тестовый период:', df_test['profit_from_client'].sum())