对于以下数据框,
d = {'col1': [33,33,33,34,34,34], 'col2': ["hello","hello1","hello2","hello3","hello4","hello5"]}
df = pd.DataFrame(data=d)
print(d)
我希望它按col1
分组,col2
中的内容作为列表连接,结果如下:
import pandas as pd
d = {'col1': [33,34], 'col2': [["hello","hello1","hello2"],["hello3","hello4","hello5"]]}
df = pd.DataFrame(data=d)
print(d)
有没有一种简单的方法可以实现这一目标?