- Делаем сводную таблицу через .groupby. , делаем функцию расчета выручки в месяц, добавляем столбец со стоимостью поездок.
- 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'})
- agg_data.columns = ['total_distance', 'total_duration', 'trip_count', 'subscription_type']
- agg_data = agg_data.reset_index()
- def income_func (row):
- if row['user_id'] in ultra['user_id'].values:
- return 6*round(row['total_duration'])+199
- if row['user_id'] in free['user_id']:
- return 8*row['total_duration']+ 50*row['trip_count']
- agg_data['income'] = agg_data.apply(income_func, axis=1)
- agg_data.head(5)
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
— Expand Paste to full width of browser