python 二维字典转矩阵

利用pandas模块

 

import pandas
books = {} books["auth1"] = {} books["auth2"] = {} books["auth1"]["humor"] = 20 books["auth1"]["action"] = 30 books["auth2"]["comedy"] = 20 from pandas import * df = pandas.DataFrame(books).T.fillna(0)
  action  comedy  humor
auth1      30       0     20
auth2       0      20      0

 

posted on 2017-11-10 10:56  chenwt  阅读(4375)  评论(0编辑  收藏  举报