python - ValueError when using pandas.read_json -
i made 250mb json file should this:
[ {"a":"uniquevalue0", "b":[1,2,3]},    {"a":"uniquevalue1", "b":[1]},    {"a":"uniquevalue2", "b":[1,2,3,4]} ]   where "b" value can variable len >= 1. this says have valid json.
i call
df = pandas.read_json('ut1.json', orient = 'records', dtype={"a":str, "b":list})   here documentation. when reading pandas dataframe, following traceback:
traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "/.../pandas/io/json.py", line 198, in read_json          date_unit).parse()   file "/.../pandas/io/json.py", line 266, in parse      self._parse_no_numpy()   file "/.../pandas/io/json.py", line 496, in _parse_no_numpy     loads(json, precise_float=self.precise_float), dtype=none) valueerror: unexpected character found when decoding 'true'   can't think of going wrong. the python file throwing error not helpful.
i had same error message, , solved using absolute path.
import os basepath = os.path.dirname(os.path.abspath(__file__)) df = pandas.read_json(basepath + '/ut1.json', orient = 'records', dtype={"a":str, "b":list})   that worked me!
Comments
Post a Comment