【发布时间】:2025-12-23 04:30:07
【问题描述】:
将嵌套字典转换为数据框,字典 keys 作为 列名 和 values 对应于这些键的 column values 的数据框。
我是python新手,尝试了几种方法,但都失败了,请帮忙。
dict= {sheet1:{col1:[a,b,c,d,e],col2:[p,q,r,s,t],col3:[l,m,n,o]},col4:[e,b,w,t,b]
sheet2:{col1:[r,w,y,g,r], col2:[q,y,f,w], col3:[w,g,4,2,d]}
output:
col1 col2 col3 col4
a p l e
b q m b
c r n w
d s o t
e t nan b
r q w nan
w y g nan
y f 4 nan
g w 2 nan
r nan d nan
【问题讨论】:
-
我认为您需要完成一些教程:您的 dict 格式不正确,将 dict 转储到 pandas 是 pandas 101。尝试:pandas.pydata.org/pandas-docs/stable/getting_started/…
-
什么是 sheet1、col1、a 等?它们是来自其他地方的字符串还是变量?
-
它们只是字符串
标签: python dataframe dictionary flatten