[英]Expected object or value error while reading json file in python
path = '/content/drive/MyDrive/gbd.json'
df = pd.read_json(path)
this is the error I am getting.
ValueError Traceback (most recent call last)
<ipython-input-11-3e269770844d> in <module>()
1 path = '/content/drive/MyDrive/gbd.json'
----> 2 df = pd.read_json(path)
6 frames
/usr/local/lib/python3.7/dist-packages/pandas/io/json/_json.py in _parse_no_numpy(self)
1138 if orient == "columns":
1139 self.obj = DataFrame(
-> 1140 loads(json, precise_float=self.precise_float), dtype=None
1141 )
1142 elif orient == "split":
ValueError: Expected object or value
我已经尝试了以下所有解决方案
data= pd.read_json('Data.json', lines=True)
data= pd.read_json('Data.json', lines=True, orient='records')
data= pd.read_json('Data.json', orient=str)
this is the link to the json file https://ccewuksprdoneregsadata1.blob.core.windows.net/data/json/publicextract.charity.zip I want to create a dataframe from the json file
我能够制作一个 DataFrame 与您的文件的一小部分提取,问题是在文件的开头有一小部分不可见的字符组,它以某种方式阻止了它。 它不会对所有编辑器都可见,我用不同的编辑器测试它是纯粹的运气。 这个字符看起来像 ,尝试用不同的编辑器打开它并删除它,它会起作用。
文件格式不正确。 尝试:
with open('publicextract.charity.json', encoding='utf-8-sig') as fp:
data = json.loads(''.join(line.strip() for line in fp))
df = pd.json_normalize(data)
Output:
date_of_extract organisation_number registered_charity_number linked_charity_number charity_name ... cio_is_dissolved date_cio_dissolution_notice charity_activities charity_gift_aid charity_has_land
0 2022-02-02T00:00:00 1 200027 1 POTTERNE MISSION ROOM AND TRUST ... None None None None None
1 2022-02-02T00:00:00 2 200027 2 HITCHAM FREE CHURCH ... None None None None None
2 2022-02-02T00:00:00 3 200028 1 TOWN LANDS CHARITY FOR THE POOR ... None None None None None
3 2022-02-02T00:00:00 4 200028 2 TOWN LANDS CHARITY FOR THE CHURCH ... None None None None None
4 2022-02-02T00:00:00 5 200034 1 CLOPHILL RELIEF IN NEED CHARITY ... None None None None None
... ... ... ... ... ... ... ... ... ... ... ...
376732 2022-02-02T00:00:00 5193574 1197688 0 FEN DRAYTON PRIMARY SCHOOL PTA ... False None None None None
376733 2022-02-02T00:00:00 5193708 1197741 0 BOLSOVER C OF E JUNIOR SCHOOL FROG ... False None None None None
376734 2022-02-02T00:00:00 5193765 1197681 0 ST MICHAEL'S RC PRIMARY PTA ... False None None None None
376735 2022-02-02T00:00:00 5193830 1197732 0 THE LIGHTHOUSE, DARWEN ... False None None None None
376736 2022-02-02T00:00:00 5193998 1197750 0 THE PENDLE FOUNDATION ... False None None None None
[376737 rows x 34 columns]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.