If Row In Dataframe Starts With Keyword, Concat It With The Row Above
I have a question similar to here but I have not been able to break through it. I have a DataFrame structured like this: 0 inner join xx 1 on xx 2 and xx 3 and yy 4 and aa 5 inner
Solution 1:
You can use groupby
+apply
:
(df.groupby((~df['join'].str.startswith('and ')).cumsum())
['join'].apply(' '.join)
)
output:
join1 inner join xx
2on xx and xx and yy and aa
3 inner join zz
Name:join, dtype: object
Post a Comment for "If Row In Dataframe Starts With Keyword, Concat It With The Row Above"