#????????? ?????? ? ????? ?????????, ??? ????? ?? ???? ??????? ?? ?????????? ? ????? ???? ??????? ?????????????? ? ?????? ???????
all_in_one = users.merge(riders, on='user_id',how='right')
all_in_one = all_in_one.merge(sub, on='subscription_type', how='left')
print(all_in_one.head())
#??????? ? ????????? ??????? ?? ???????? ? ???????? - ???
riders_ultra = all_in_one.query('subscription_type =="ultra"')
riders_free = all_in_one.query('subscription_type =="free"')
#??????? ??????? ??????? ??????? .groupby
agg_data = all_in_one.groupby(['user_id','month']).agg({'distance':'sum','duration':['sum','count']})
#??????? ??????? ? ????????? ??????? ? ???????
agg_data.columns = ['distance_sum', 'duration_sum', 'rides_count']
agg_data = agg_data.reset_index()
#????????? ??????? ??????? ??????? ? ?????
def income_func (row):
if row['user_id'] in riders_ultra['user_id']:
return 6*row['duration_sum'].round()+199
if row['user_id'] in riders_free['user_id']:
return 8*row['duration_sum']+ 50*row['rides_count']
#??????? ??????? ?? ?????????? ???????, ???????? ??????? ? ?????? ?????? agg_data
agg_data['income'] = agg_data.apply(income_func, axis=1)
print(agg_data.head(15))
print(agg_data.tail(15))
Re: Re: Untitled
From Small Bushbaby, 7 Months ago, written in Plain Text, viewed 182 times.
This paste is a reply to Re: Untitled from Sole Mosquito
- go back
URL http://codebin.org/view/a13512e6/diff
Embed
Viewing differences between Re: Untitled and Re: Re: Untitled
— Expand Paste to full width of browser