最佳答案
假设您的数据框的变量名称是“df”,那么下面可能会有所帮助:
temp = df.groupby(['labels']).apply(lambda x: x['tweets'].tolist()).to_dict()
print(temp)
关于python - 将 Pandas 数据框转换为字典,其中一列作为键,另一列作为多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71121233/