Python: 如果将字典转化为DataFrame
这样的字典:
D = {"A1":["T1"], "A2":["T1","T2"],
"A3":["T1","T2","T3","T4"],
"A4":[]
"A5":["T1"]}
如何转化为如下的DataFrame:
Item | Value |
---|---|
A1 | T1 |
A2 | T1 |
A2 | T2 |
A3 | T1 |
A3 | T2 |
A3 | T3 |
A3 | T4 |
A5 | T1 |
回答:
import pandas as pdD = {"A1":["T1"],
"A2":["T1","T2"],
"A3":["T1","T2","T3","T4"],
"A4":[],
"A5":["T1"]}
df = pd.DataFrame([(k, e) for k, v in D.items() for e in v])
回答:
请百度pandas的DataFrame()函数
以上是 Python: 如果将字典转化为DataFrame 的全部内容, 来源链接: utcz.com/a/165545.html