Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. DATA_FOLDER = '../readonly/final_project_data/'
  4. transactions = pd.read_csv(os.path.join(DATA_FOLDER, 'sales_train.csv.gz'), )
  5.  
  6. transactions['date'] = pd.to_datetime(transactions['date'])
  7. grouped_sum = transactions[(transactions['date'].dt.year == 2013) & (transactions['date'].dt.month == 9)].groupby('item_id').sum()
  8.  
  9. def calc(df):
  10. return df['item_price'] * df['item_cnt_day']
  11.  
  12. grouped_sum['total_revenue'] = grouped_sum.apply(calc, axis=1)
  13. max_revenue = grouped_sum.sort_values('total_revenue', ascending=False).iloc[0,4]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement