Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我有一个列表和字典的元组,如何在python中将其转换为dataframe?_Python_Pandas_List_Dictionary_Tuples - Fatal编程技术网

我有一个列表和字典的元组,如何在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