Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.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_Python 3.x_Pandas - Fatal编程技术网

Python 将字典集合转换为数据帧

Python 将字典集合转换为数据帧,python,python-3.x,pandas,Python,Python 3.x,Pandas,我有一个dictionary列表,我想将其转换为DataFrame列,其中dictionary键是python3.5中DataFrame列的列 以下是我当前收藏的结构: 我想将其转换为熊猫数据帧,如下所示: Col1 Col2 Col3 2.17 41.1 1 我解决了这个问题,下面的代码允许您提取数据帧列中的dict元素 以下是原始记录格式: 输出为: 希望这有帮助 为什么不把它作为文本?如果你有一个字典列表,你可以简单地做pandas.DataFrameextracted[

我有一个dictionary列表,我想将其转换为DataFrame列,其中dictionary键是python3.5中DataFrame列的列

以下是我当前收藏的结构:

我想将其转换为熊猫数据帧,如下所示:

Col1   Col2  Col3
2.17   41.1  1

我解决了这个问题,下面的代码允许您提取数据帧列中的dict元素

以下是原始记录格式:

输出为:


希望这有帮助

为什么不把它作为文本?如果你有一个字典列表,你可以简单地做pandas.DataFrameextracted['data']?你似乎有一系列完整的字典,而不是一个列表。你是怎么得到这个系列的?您可能应该更改创建此对象的代码,而不是对其进行后处理。@treegarden此建议不起作用。我已经试过了。那么它很可能不是一个dict列表,正如@user2357112所暗示的那样。为什么实际答案的列标题被删掉了?
# Extract message details into a new dataframe
s = pd.Series(extracted['data']).dropna()
cols = ['Col1','Col2','Col3','Col4']
rows = []

for idx,i in enumerate(s): 
    row = [i['Col1'],i['Col2'],i['Col3'],i['Col4']]
    rows.append(row)
    
sensors = pd.DataFrame(rows, columns = cols)
sensors.head()