I have a PANDAS dataframe with a two line index. I want to keep certain columns based on the second line index. How could I do it? I have tried a few things but nothing worked. For example, consider the following dataframe:
AAA BBB CCC
C1 C2 C3 C1 C2 C3 C1 C2 C3
Index
1 1 2 3 4 5 6 1 2 3
2 2 5 0 7 8 9 7 4 5
3 7 4 1 5 7 2 2 5 9
How can I keep only column C2 for all cases (i.e. for AAA, BBB, CCC). As a result I would like to have:
AAA BBB CCC
C2 C2 C2
Index
1 2 5 2
2 5 8 4
3 4 7 5
Thanks in advance for the help.