I would like to add columns into a Pandas multiindex dataframe, which will contain the result of an operation performed on other columns.
I have a dataframe similar to this one:
first   bar     baz     
second  one two one two
A       5   2   9   2   
B       6   4   7   6   
C       5   4   5   1   
Now, for each group in the dataframe, I'd like to add a column "three" which equals column "one" minus column "two":
first   bar             baz     
second  one two three   one two three
A       5   2   3       9   2   7
B       6   4   2       7   6   1
C       5   4   1       5   1   4
In reality my dataframe is much larger. I'm struggling to find the answer to this (hopefully) easy question. Any suggestions are appreciated.
 
     
    