对于定义的字典data = { 'row1' : [1,2,3,4], 'row2' : ['a' , 'b' , 'c' , 'd'] },

按照官方文档方法,将其转化为dataframe:

不定义列名时:

pd.DataFrame.from_dict(data, orient='index')

结果如下:

         0 1 2 3

row1   1 2 3 4

row2  a b c d

定义列名时:

pd.DataFrame.from_dict(data, orient='index', columns=['A', 'B', 'C', 'D'])

结果应该如下:

         A B C D

row1   1 2 3 4

row2  a b c d

但这时候python3会报错:from_dict() got an unexpected keyword argument 'columns'

这是因为你的pandas不是最新的,columns :New in version 0.23.0

可以更新pandas或者使用另一种方法,如下:

pd.DataFrame(list(my_dict.items()), columns=['A', 'B'])