pandas apply function on multiindex
问题 I would like to apply a function on a multiindex dataframe (basically groupby describe dataframe) without using for loop to traverse level 0 index. Function I'd like to apply: def CI(x): import math sigma = x["std"] n = x["count"] return 1.96 * sigma / math.sqrt(n) Sample of my dataframe: df = df.iloc[47:52, [3,4,-1]] a b id 47 0.218182 0.000000 0d1974107c6731989c762e96def73568 48 0.000000 0.000000 0d1974107c6731989c762e96def73568 49 0.218182 0.130909 0d1974107c6731989c762e96def73568 50 0