我有一个 Pandas DataFrame: text is_from_me0 Happy birthday bud!!! 11 Thanks man! 02 Definitely would've come back had I thought ab... 13 Your good 04 Okay haha 15 Have a good one 16 Yea you too. What are you up to? 07 No hw like I'm doing all day 18 Just got up 19 Same here. I went to the football game last... 010 I think I saw that in your story 111 Win? 112 Lost in last second 013 Aw, that sucks 114 Means it was a good game tho? 115 Really good game. They were on the 1/2 yard li... 016 Dang 1我正在尝试制作以下内容: input output0 Happy birthday bud!!! Thanks man! 2 Thanks man! Definitely would've come back had I thought ab...3 Definitely would've come back had I thought ab... Your good4 Your good Okay haha\nHave a good one我可以用这段代码完成一些接近的事情:pd.concat([df['text'].reset_index(drop=True), df['text'].shift(-1).reset_index(drop=True)], axis=1)但是,这不会根据is_from_me组的文本与分隔原始字符串的换行符组合的位置来组合文本。这是一个简单的例子,可能会有多于 2 行的行组合成一行。我已经尝试想出一种简单的方法来定义这个分组,但我所能管理的只是一个令人费解的 for 循环,它有点以一种hacky 的方式完成这项工作。是否有我可以编写的聚合函数可以为我完成此任务?
添加回答
举报
0/150
提交
取消