给定dataframer如下:

python dataframe转dict

可以用to_dict()转成dict,转的时候通过指定orient参数来实现不同的方式:

python dataframe转dict

 

如果想得到cat_nums和avg_length的字典,可以有两种方式:

第一种方式:

python dataframe转dict

第二种方式,把cat_nums变成index,然后使用上述的to_dict()

 

 

 

相关文章: