我有一个熊猫数据框:
from pandas import DataFrame
import pandas as pd
df2 = DataFrame({'a' : ['one', 'one', 'two','two', 'three', 'two', 'one', 'six'],
'b' : ['x', 'y', 'z', 'y', 'x', 'y', 'x', 'x']})
我需要使用列对其进行分组'a'
.
df3 = df2.groupby(['a'])
接下来,我要转换列'b'
转换为逗号分隔的字符串,结果表应如下所示:
a b
---------------
one j, k, l
two m, n, o
three p, q
有谁知道如何在不离开熊猫的情况下做到这一点?这看起来很简单,但找不到在 pandas 内部实现的方法。