试过很多方法
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)
'''