Python: 如果将字典转化为DataFrame

Python: 如果将字典转化为DataFrame

这样的字典:

D = {"A1":["T1"],

"A2":["T1","T2"],

"A3":["T1","T2","T3","T4"],

"A4":[]

"A5":["T1"]}

如何转化为如下的DataFrame:

ItemValue
A1T1
A2T1
A2T2
A3T1
A3T2
A3T3
A3T4
A5T1


回答:

import pandas as pd

D = {"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

回到顶部