我有一个字典,其中列表是值,例如:
cols = {'animals':['dog','cat','fish'],
'colors':['red','black','blue','dog']}
我希望将此转换为数据框,在其中每个列表根据其键进行枚举,结果为什么。key variable
animals dog
animals cat
animal fish
colors red
colors black
colors blue
colors dog
到目前为止,我已经做了这个:但它并没有给我想要的结果。
cols_df = pd.DataFrame.from_dict(cols, orient='index')
如何修改此内容以实现以上目标?
from_dict(.. orient='index')
只提供宽格式,而from_dict(.. orient='columns')
则会出现ValueError('arrays must all be same length')
的错误。 - smci