python 读json 错误 ValueError: Unexpected character found when decoding array value (2)

  统计/机器学习 数据预处理 Python I/O    浏览次数:9736        分享
0

试过很多方法 

StackOverflow的方法都无效


# -*- coding: utf-8 -*-
"""
Created on Mon Mar 9 07:19:44 2020
"""
import pandas as pd
import json
import codecs
import os
#basePath = os.path.dirname(os.path.abspath(__file__))
#data=pd.read_json(basePath+'/data.json',orient='values',lines=True)
data=pd.read_json(r"C:\mypython\308json\data.json", encoding="utf8",lines=True)
'''
# read the entire file into a python array
with open('data.json', 'rb') as f:
    data = f.readlines()
# remove the trailing "\n" from each line
data = map(lambda x: x.rstrip(), data)
# each element of 'data' is an individual JSON object.
# i want to convert it into an *array* of JSON objects
# which, in and of itself, is one large JSON object
# basically... add square brackets to the beginning
# and end, and have all the individual business JSON objects
# separated by a comma
data_json_str = "[" + ','.join(data) + "]"
# now, load it into pandas
data_df = pd.read_json(data_json_str)
'''
'''
with open('data.json', encoding="utf8") as f:
    data = f.readlines()
    data = [json.loads(line) for line in data] #convert string to dict format
df = pd.read_json(data) # Load into dataframe
'''
#data=pd.read_json(codecs.open('data.json','r','utf-8'),lines=True)
'''
with open('data.json','rb') as f:
  entries=f.readlines()
lines=list(entries)
Cleaned=[str(line).rstrip() for line in lines]
#Removes \n
Json="[" + ','.join(str(cl) for cl in Cleaned) + "]"
data=pd.read_json(Json)
'''


 

constant007   2020-03-09 09:13



    还没有回答。我来答!  


  相关讨论

怎么把多个csv表格读进python然后合并成一个表格输出为csv?

怎么把python的dict存为json格式文件

python如何读取元素中含有逗号的csv文件

怎么在python中读取mat格式数据文件?

python能不能直接读取word文本,doc或者docx文件?

python怎么读取txt格式的数据文件?

怎么把statsmodels训练的模型本地保存?

pandas怎么读入tsv格式的数据

pd.read_csv读取数据时自动跳过空白行

关于如何读取文件效率最高,最节约内存?

  随便看看

随机森林会发生过拟合(overfitting)吗?

协方差矩阵一定是半正定的吗?

为什么梯度的反方向是函数下降最快的方向?

单一变量下的异常检测该怎么做?

matplotlib一个画板上多个图叠加,如何决定图层上下?