I am looking for a way to add a higher level column index in pandas.
I have a multiindexed pandas dataframe like this:
>>>df
product A B C
sell_buy sell buy sell buy sell buy
group company
1 Bank X 100 50 200 10 20 20
2 Bank Y 20 40 150 40 30 20
3 Bank Z 100 20 20 10 40 10
I want to add a higher level index in columns from company, and set a row index with the date of today (using something like datetime.today())
company Bank X Bank Y Bank Z
product A B C A B C A B C
sell_buy sell buy sell buy sell buy sell buy sell buy sell buy sell buy sell buy sell buy
2020-08-15 100 50 200 10 20 20 20 40 150 40 30 20 100 20 20 10 40 10
I tried several attempts, but I cannot figure out how to make it work...
pd.MultiIndex.from_product([df.columns.levels, ['Bank X']])
pd.MultiIndex.from_product([df.columns.levels, ['product']])
Any help would be appreciated. Thank you!