a guest Jan 24th, 2020 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. data_final = pd.read_csv('/datasets/data_final.csv')
  3. data_pivot = data_final.pivot_table(index=['category_name', 'subcategory_name'], columns='source', values='visits', aggfunc='sum')
  4. data_pivot['ratio'] = data_pivot['organic'] / data_pivot['direct']
  5. data_pivot = data_pivot.sort_values(by='ratio', ascending=False)
  6. print(data_pivot.head(10))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand