Untitled

From Soiled Teal, 2 Months ago, written in Plain Text, viewed 56 times.
URL http://codebin.org/view/b4d89b2f Embed
Download Paste or View Raw
  1. def get_prices(type):
  2.     if type == 'A':
  3.         return 1000, 400
  4.     if type == 'B':
  5.         return 800, 350
  6.     if type == 'C':
  7.         return 600, 350
  8.     if type == 'D':
  9.         return 550, 150
  10.     if type == 'E':
  11.         return 500, 150
  12.     if type == 'F':
  13.         return 450, 150
  14.  
  15. def profit_from_client(row):
  16.     room_price, service_price = get_prices(row['reserved_room_type'])
  17.     if row['arrival_date_month'] == 'December' or row['arrival_date_month'] == 'January' or row['arrival_date_month'] == 'February':
  18.         n = 1
  19.     elif row['arrival_date_month'] == 'June' or row['arrival_date_month'] == 'July' or row['arrival_date_month'] == 'August':
  20.         n = 1.4
  21.     else:
  22.         n = 1.2
  23.    
  24.     if row['is_canceled'] == 1:
  25.         return -(room_price * n + service_price)
  26.     else:
  27.         return room_price * n - service_price * (1 + row['total_nights'] // 2)
  28.    
  29. df_train['profit_from_client'] = df_train.apply(profit_from_client, axis=1)
  30. print('Прибыль для обучающей выборки:', df_train['profit_from_client'].sum())
  31. df_test['profit_from_client'] = df_test.apply(profit_from_client, axis=1)
  32. print('Прибыль за тестовый период:', df_test['profit_from_client'].sum())

Reply to "Untitled"

Here you can reply to the paste above