Iteratively Concatenate Columns In Pandas With Nan Values
I have a pandas.DataFrame data frame: import pandas as pd df = pd.DataFrame({'x': ['hello there you can go home now', 'why should she care', 'please sort me appropriately'],
Solution 1:
Option 1
pd.Series(df.fillna('').values.tolist()).str.join(' ')0 hello there you can go home now
1 why should she care finally we were able to go...
2 please sort me appropriately but what about me...
dtype:object
Option 2
df.fillna('').add(' ').sum(1).str.strip()0 hello there you can go home now
1 why should she care finally we were able to go...
2 please sort me appropriately but what about me...
dtype:object
Post a Comment for "Iteratively Concatenate Columns In Pandas With Nan Values"