In the following DataFrame: How can I replace ["x2", "Total"] with ["x2", "x2"] leaving x1 as is?
l1 900 902 912 913 916
l2 ИП ПС ИП ПС ИП ПС ИП ПС ИП ПС
i1 i2
x1 Total 10 6 3 3 10 16 2 9 3 8
x2 Total 1 0 0 0 0 0 0 0 0 0
.rename will replace all "Total" values, not just the one I need.
Assuming your dataframe is called df the following code will perform your desired substitution by replacing the existing index with a modified index.
Or you can directly modify the inner level of the index:
You can also use
level='i2'in place oflevel=1