我的数据示例:
name day text
john 1 october hello
john 1 october world
mary 1 october good friend
john 1 october python is cool
peter 1 october love is
peter 1 october in the air
当列“name”和“day”在连续行中相同时,我想连接“text”。“day”不总是“1 October”,并且数据集非常大。这就是我想要的:
name day text
john 1 october hello world
mary 1 october good friend
john 1 october python is cool
peter 1 october love is in the air
下面是我的代码:
data = data.fillna(' ')
data = data.groupby(['name', 'day'], as_index=False).agg({'text': ' '.join})
我正在获得但不是我想要的东西:
name day text
john 1 october hello world python is cool
mary 1 october good friend
peter 1 october love is in the air
我应该如何更改我的代码?
1条答案
按热度按时间8nuwlpux1#
用
shift
、any
和cumsum
制作一个定制的石斑鱼:输出: