I'm looking for some help understanding the results of the below. Why do I get NaN for df.loc[1, 'c2']? Since I don't get the same type of error when there is only one index, it must have something to do with not specifying the second level of the multi-index in the calculation, but I'm having trouble figuring out the exact problem. Why does it only work when I use .values?
df = pd.DataFrame({'i': [1,1,2,2], 'i2':[1,2,1,2], 'a':[10,20,30,40], 'b':[100,100,300,400]})
df = df.set_index('i')
df.loc[1, 'c1'] = df.loc[1, 'a'] / df.loc[1, 'b'] #Works
df = df.reset_index()
df = df.set_index(['i', 'i2'])
df.loc[1, 'c2'] = df.loc[1, 'a'] / df.loc[1, 'b'] #Fails (NaN)
df.loc[1, 'c2'].index.equals(df.loc[1, 'a'].index) #True
df.loc[1, 'c2'].index.equals(df.loc[1, 'b'].index) #True
df.loc[1, 'c3'] = df.loc[1, 'a'].values / df.loc[1, 'b'].values #Works
df.loc[1, 'c4'] = (df.loc[1, 'a'] / df.loc[1, 'b']).values #Works