Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.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 使用.csv文件中的熊猫访问JSON子属性_Python_Json_Python 3.x_Pandas - Fatal编程技术网

Python 使用.csv文件中的熊猫访问JSON子属性

Python 使用.csv文件中的熊猫访问JSON子属性,python,json,python-3.x,pandas,Python,Json,Python 3.x,Pandas,我有这个嵌套的JSON数据集,我已使用pandas将其转换为.csv: [{ "attribute1": "One", "attribute2": "Two", "attribute3": [{ "attribute4": "Four", "attribute5": "Five" }, { "attribute4": "Four", "a

我有这个嵌套的JSON数据集,我已使用
pandas
将其转换为
.csv

[{
        "attribute1": "One",
        "attribute2": "Two",
        "attribute3": [{
            "attribute4": "Four",
            "attribute5": "Five"
        }, {
            "attribute4": "Four",
            "attribute5": "Five"
        }]
    }]

df = pd.DataFrame(data, columns=["attribute1", "attribute2", "attribute3"])
df.to_csv('example.csv')
attribute3
列中的数据仍然是JSON。如何使用索引访问
attribute3
的子属性值,即
attribute4
attribute5
? 例如:
data[0][2:0]
用于获取第0行、第二列及其子属性zero的数据


如果能提供一些关于如何访问嵌套值的帮助,我将不胜感激。我应该展平包含嵌套值的单个列吗?我该怎么做

使用以下方法解析原始JSON(
数据
)会更容易:

In [5]: pd.io.json.json_normalize(data, ['attribute3'], ['attribute1','attribute2'])
Out[5]:
  attribute4 attribute5 attribute1 attribute2
0       Four       Five        One        Two
1       Four       Five        One        Two