Re: Untitled

From Sole Mosquito, 4 Months ago, written in Plain Text, viewed 120 times. This paste is a reply to Untitled from Sole Shama - view diff
URL http://codebin.org/view/9556b4c7 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 Re: Untitled rss

Title Name Language When
Re: Re: Untitled Small Bushbaby text 4 Months ago.

Reply to "Re: Untitled"

Here you can reply to the paste above