python中当dict转dataframe时候报错:All arrays must be of the same length解决方法

dic = defaultdict(list)

dic[1]=[1,2,3,4]

dic[2]=[2,1,0,12]

pd.DataFrame(dic)  #报错:All arrays must be of the same length

解决方法:

dic = defaultdict(list)

dic[1]=[1,2,3,4]

dic[2]=[2,1,0,12]

lll = []
for i in dic.keys():
    lll.append(dic[i])
pd.DataFrame(lll)

你可能感兴趣的:(python,开发语言)