Pandas: merge columns with the similar names

Viewed 598
Politics  Politics  Politics    Arts/Culture  Arts/Culture  Arts/Culture
  nan       nan        c         nan            nan          c
  nan        b         nan        a             nan          nan
  nan        b         nan        a             nan          nan
  a          nan       nan        nan           c            nan   

Basically, this goes on throughout the dataframe. I want to merge the similar columns to the dataframe below

Politics    Arts/Culture  
 c              c
 b              a
 b              a
 a              c

2 Answers

Try with groupby with level=0 and axis=1 then do first

s=df.groupby(level=0,axis=1).first()
  Arts/Culture Politics
0            c        c
1            a        b
2            a        b
3            c        a
Related