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
Use DataFrame.stack
+ DataFrame.unstack
:
df1 = df.stack().unstack()
Result:
# print(df1)
Arts/Culture Politics
0 c c
1 a b
2 a b
3 c a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With