Consider the following data:
d = { 'app' : ['J', 'J', 'J', 'J', 'J', 'J', 'J', 'J', 'J', 'B'], 'geo': ['US', 'US', 'US', 'Asia', 'Asia', 'Asia', 'Europe', 'Europe', 'Europe', 'US'], 'device': ['iPhone', 'iPad', 'Android', 'iPhone', 'iPad', 'Android', 'iPhone', 'iPad', 'Android', 'iPhone'], 'cost': [4500, 4000, 4500, 2000, 2000, 2500, 500, 500, 500, 250]}
df = pd.DataFrame(d)
and a pivot out of it
df_pivoted = pd.pivot_table(df, index = 'app', columns=['geo', 'device'], values=['cost'], aggfunc=np.sum)
df.loc[['J'], ('cost', 'Asia')]
0 comments:
Post a Comment