0

I'm surprised, i haven't found anything relevant.

I simply need to flattern this DataFrame with some unifying symbol, e.g. "_".

So, i need this

           A        B   
         a1 a2    b1 b2 
id                                                                                  
264    0    0     1   1 
321    1    1     2   2

to look like this:

         A_a1 A_a2    B_b1 B_b2 
id                                                                                  
264       0    0       1    1   
321       1    1       2    2
Ladenkov Vladislav
  • 1,247
  • 2
  • 21
  • 45
  • @Wen, please also link this dup which has more detail: https://stackoverflow.com/questions/14507794/python-pandas-how-to-flatten-a-hierarchical-index-in-columns?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – jpp Apr 04 '18 at 15:53
  • Thanks. It's really strange, that i was offered to check a bunch of very different questions, but was not directed to it... – Ladenkov Vladislav Apr 04 '18 at 16:07

1 Answers1

2

Try this:

df.columns = df.columns.map('_'.join)
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419