在python中读取json文件时出错:需要object或valu

2024-06-26 15:01:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我把这个json文件保存在我的jupyter笔记本中,我想读一下:

[
    {   'category_type': 'c',
        'modification_type': 'fixed',
        'modification_list': 0 ,
        'features_list': ['feature1','feature2']
    },
    {   'category_type': 'continious',
        'modification_type': 'fixed_list',
        'modification_list': 1 ,
        'suffix': '_1',
        'features_list': ['feature3','feature4']
    }
]

该文件保存在jupyter notebook主页上的文件夹中,我正在尝试使用以下代码读取该文件:

pd.read_json('folder/file.json', orient='records',encoding='utf-8')

但我一直得到这个错误:ValueError:预期的对象或值

有谁能帮忙解决这个问题吗?你知道吗


Tags: 文件jsontype笔记本jupytersuffixlistfixed
1条回答
网友
1楼 · 发布于 2024-06-26 15:01:42

要将json作为数据帧读取,只需使用以下几行代码。我想那是你的问题

import pandas as pd
import numpy as np


# Load the first sheet of the JSON file into a data frame
data_df = pd.read_json('reviewsclean.json', lines=True)

相关问题 更多 >