Re: Re: Untitled

From Bistre Cockroach, 10 Months ago, written in Plain Text, viewed 124 times. This paste will give up the ghost in 1 Second. This paste is a reply to Re: Untitled from Putrid Frog - view diff
URL http://codebin.org/view/7f28297c Embed
Download Paste or View Raw
  1. Делаем сводную таблицу через .groupby. , делаем функцию расчета выручки в месяц, добавляем столбец со стоимостью поездок.
  2.  
  3. agg_data = data.pivot_table(index=['user_id', 'month'], values = ['distance', 'duration', 'name', 'subscription_type'], aggfunc={'distance':'sum', 'duration':'sum', 'name':'count', 'subscription_type': 'min'})
  4.  
  5. agg_data.columns = ['total_distance', 'total_duration', 'trip_count', 'subscription_type']
  6.  
  7. agg_data = agg_data.reset_index()
  8.  
  9. def income_func (row):
  10.     if row['user_id'] in ultra['user_id'].values:
  11.         return 6*round(row['total_duration'])+199
  12.     if row['user_id'] in free['user_id']:
  13.         return 8*row['total_duration']+ 50*row['trip_count']
  14.  
  15. agg_data['income'] = agg_data.apply(income_func, axis=1)      
  16.  
  17. agg_data.head(5)
  18.  

Reply to "Re: Re: Untitled"

Here you can reply to the paste above