问题遇到的现象和发生背景
将df中的数据,根据col0来进行分组,col3里的一组的合并为一个列表
问题相关代码,请勿粘贴截图
df = df[['col0', 'col3']]
df_new = df.groupby('col0')['col3'].apply(lambda x:x.str.cat(sep = ',')).reset_index()
print(df)
print(df_new)
运行结果及报错内容
TypeError: Cannot use .str.cat with values of inferred dtype 'mixed'.