Let's say I have a DataFrame like this:
df = pd.DataFrame(data = [[1,2,3,4,5,6], [3,4,5,6,7,8]], 
                  columns = pd.MultiIndex.from_product([('A1', 'B1', 'A2'), (10,20)], names=['level_0','level_1']))
Here's how it looks like: DataFrame image
I want to add a new level in the columns which contains 1 where level_0 value contains "1" and and 2 where level_0 value contains "2". So, basically:
- Where level_0 == "A1"-->new_level=1
- Where level_0 == "B1"-->new_level=1
- Where level_0 == "A2"-->new_level=2
Any suggestions on how to do it?
 
     
    