我有一个列表和字典的元组,如何在python中将其转换为dataframe?
这就是原始数据的样子 输入 这是必需的输出 所需输出:我有一个列表和字典的元组,如何在python中将其转换为dataframe?,python,pandas,list,dictionary,tuples,Python,Pandas,List,Dictionary,Tuples,这就是原始数据的样子 输入 这是必需的输出 所需输出: sr_no a b c d e f g h I 1 1 -50 1 True PM NaN NaN NaN NaN 2 2 1 101 1 1 False True False MLTPL 3 3 1 103 1 1
sr_no a b c d e f g h I
1 1 -50 1 True PM NaN NaN NaN NaN
2 2 1 101 1 1 False True False MLTPL
3 3 1 103 1 1 False True False MLTPL
输出:
a b c d e f g h I
1 1 -50 1 True PM NaN NaN NaN NaN
2 2 1 101 1 1 False True False MLTPL
3 3 1 103 1 1 False True False MLTPL
请不要参考我在这里输入的代码
data = \
[(1, {"a":1,"b":-50,"c":1, "d":True, "e":"PM"}),
(2, {"a":2,"b":1,"c":"101","d":1,"e":1,"f":False,"g":True,"h":False,"I":"MLTPL"}),
(3, {"a":3,"b":1,"c":"103","d":1,"e":1,"f":False,"g":True,"h":False,"I":"MLTPL"})]
data = dict(data) # a dictinoary is a much better format
pd.DataFrame.from_dict(data, orient = 'index') # initialize using pandas built in dict reader
a b c d e f g h I
1 1 -50 1 True PM NaN NaN NaN NaN
2 2 1 101 1 1 False True False MLTPL
3 3 1 103 1 1 False True False MLTPL