Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.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 数据帧内带听写功能的词典_Python_Pandas_Dictionary_Dataframe - Fatal编程技术网

Python 数据帧内带听写功能的词典

Python 数据帧内带听写功能的词典,python,pandas,dictionary,dataframe,Python,Pandas,Dictionary,Dataframe,我有一个结构如下的dict: {'periodicity' : 'false', 'load' : '45', 'cell' : '33', 'capacity' : '20' 'SList' : [{'sPer' : '22', 'sRep' : '43', 'sMes' : 's5'}, {'sPer' : '22', 'sRep' : '43', 'sMes' : 's6'}, {'sPer' : '22', 'sRep' : '43',

我有一个结构如下的dict:

{'periodicity' : 'false',
 'load' : '45',
 'cell' : '33',
 'capacity' : '20'
 'SList' : [{'sPer' : '22',
   'sRep' : '43',
   'sMes' : 's5'},
  {'sPer' : '22',
   'sRep' : '43',
   'sMes' : 's6'},
  {'sPer' : '22',
   'sRep' : '43',
   'sMes' : 's7'}],
 ...}
我用那个dict生成了dataframe。问题是我得到了3行值完全相同的数据,除了SList列,你可以看到原因,但我只需要一个dict,如下所示:

periodicity     load      cell     capacity                                 SList
  false          45        33         20          {'sPer' : '22','sRep' : '43','sMes' : 's5'}, {'sPer' : '22', 'sRep' : '43', 'sMes' : 's6'}, ...
问题出在哪里?

通过指定字典的键必须作为索引标签传递,使用
orient=“index”
并将其转置:

pd.DataFrame.from_dict(d, orient="index").T

或者,让我们直接为您进行解析:

from pandas.io.json import json_normalize
json_normalize(d)
这两种方法都产生:

通过指定字典的键必须作为索引标签传递,使用
orient=“index”
并将其转置:

pd.DataFrame.from_dict(d, orient="index").T

或者,让我们直接为您进行解析:

from pandas.io.json import json_normalize
json_normalize(d)
这两种方法都产生: