For my test I used the following DataFrame (using Latin characters
as column names and index):
Volume Sale
YTD2017 YTD2018 YTD2019 YTD2017 YTD2018 YTD2019
A 212.0 220.0 226.16 3654.04 4163.87 4695.12
B 17.5 18.5 18.57 234.84 274.47 298.90
C 18.5 14.5 12.66 213.02 191.14 177.46
My first observation is that df.Sale / df.Volume alone does work,
so let's save the result in an auxiliary DataFrame (df2).
So far we have:
YTD2017 YTD2018 YTD2019
A 17.236038 18.926682 20.760170
B 13.419429 14.836216 16.095854
C 11.514595 13.182069 14.017378
This result can not be joined to the original df, because df has a
MultiIndex as columns, whereas df2 has an "ordinary" index.
But we can add the missing index level to columns in df2:
df2.columns = pd.MultiIndex.from_product([['Price'], df2.columns])
Now df2 contains also a MultiIndex on columns:
Price
YTD2017 YTD2018 YTD2019
A 17.236038 18.926682 20.760170
B 13.419429 14.836216 16.095854
C 11.514595 13.182069 14.017378
So now there is no obstacle to join these 2 DataFrames:
df = df.join(df2)
getting:
Volume Sale Price
YTD2017 YTD2018 YTD2019 YTD2017 YTD2018 YTD2019 YTD2017 YTD2018 YTD2019
A 212.0 220.0 226.16 3654.04 4163.87 4695.12 17.236038 18.926682 20.760170
B 17.5 18.5 18.57 234.84 274.47 298.90 13.419429 14.836216 16.095854
C 18.5 14.5 12.66 213.02 191.14 177.46 11.514595 13.182069 14.017378