Reputation: 913
Chat A B C D ...... X
0 I'm groot Nan Nan Nan Nan
1 I am rocket Nan Nan Nan
I have a df with multiple columns contain Strings in it and some of them are Nan I want to merge them all into one column and drop the rest. The result should be something like this:
Chat
0 I'm groot
1 I am rocket
Upvotes: 0
Views: 136
Reputation: 402323
fillna
+ str.join
Fill, join, and cleanup:
df = df.fillna('').agg(' '.join, 1).str.replace('\s{2,}', ' ').str.strip()
df
Chat
0 I'm groot
1 I am rocket
Upvotes: 2