import numpy as np
import pandas as pd
data = {'experiment_name': ['exp1', 'exp1', 'exp1', 'exp1', 'exp1', 'exp1'],
'variant': ['A', 'B', 'A','B','A','B'],'sessions_with_orders':[1,2,6,0,23,12],
'total_sessions':[10,23,56,22,89,12]}
# Create DataFrame
df = pd.DataFrame(data)
df.pivot_table(index='variant',columns='experiment_name',values=['total_sessions','sessions_with_orders'],aggfunc=np.sum)
I have some data frame where I pivot it using aggregate functions.
The output I get is desired. However, I would like to create ratio sessions_with_orders/total_sessions. How do I do this? That is doable on excel but I am unable to think over pandas-data frame.
I do not understand lambda, cross_tab or how to implement them.
I am on python 3.9.8. np-version 1.22.3 and pd-version 1.3.4