df 为dataframe对象,包含'word', 'count'两列数据
result_dic = df.groupby('word')['count'].apply(lambda x:str(x)).to_dict()
result_dic = df.groupby('word')['count'].apply(lambda x:x).to_dict()
这是为什么呢,求解。
第一个应用了 str(x) 将 元素转换为字符串类型了,第二种没有转换还是原来的类型。
.to_dict(orient='list),这样不带index