Untitled

From Sole Shama, 7 Months ago, written in Plain Text, viewed 110 times.
URL http://codebin.org/view/118c5591 Embed
Download Paste or View Raw
  1. #соберем сводную таблицу методом .groupby
  2. agg_data = all_in_one.groupby(['user_id','month']).agg({'distance':'sum','duration':['sum','count']})
  3. #наведем красоту в названиях колонок и идексах
  4. agg_data.columns = ['distance_sum', 'duration_sum', 'rides_count']
  5. agg_data = agg_data.reset_index()
  6. #объявляем функцию расчета выручки в месяц
  7. def income_func (row):
  8.     if row['user_id'] in riders_ultra['user_id']:
  9.         return 6*row['duration_sum'].round()+199
  10.     if row['user_id'] in riders_free['user_id']:
  11.         return 8*row['duration_sum']+ 50*row['rides_count']
  12. #добавим столбец со стоимостью поездок, применив функцию к каждой строке agg_data
  13. agg_data['income'] = agg_data.apply(income_func, axis=1)      
  14. print(agg_data.head(15))
  15. print(agg_data.tail(15))

Replies to Untitled rss

Title Name Language When
Re: Untitled Sole Mosquito text 7 Months ago.

Reply to "Untitled"

Here you can reply to the paste above