Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix ```ValueError: Trailing data``` during ```pandas.read_json(...)```?

I'm trying to read a JSON file into a Pandas dataframe, in the following:

def read_JSON_into_dataframe( file_name ):
    with sys.stdin if file_name is None else open( file_name, "r", encoding='utf8', errors='ignore' ) as reader:
        df = pd.read_json( reader )
        print( df.describe(), file = sys.stderr )
        return df

However, I'm getting an error, for which to bottom stack frame is:

C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\json\json.py in _parse_no_numpy(self)
    869         if orient == "columns":
    870             self.obj = DataFrame(
--> 871                 loads(json, precise_float=self.precise_float), dtype=None)
    872         elif orient == "split":
    873             decoded = {str(k): v for k, v in compat.iteritems(

ValueError: Trailing data

What does "trailing data" refer to? If it refers to some point in the JSON file, is there something I can do to figure out where that is and what's wrong with it?

like image 525
Mark Lavin Avatar asked Oct 11 '19 17:10

Mark Lavin


People also ask

How do I fix Valueerror trailing data?

The easiest way to fix this error is to simply specify lines=True when importing the data: #import JSON file into pandas DataFrame df = pd.

What does Trailing data mean?

What Is Trailing? Trailing refers to the property of a measurement, indicator, or data series that reflects a past event or observation. It is usually attached to a specified time interval by which the data trail or over which that data are aggregated, summed, or averaged.

How do I read a JSON file in Python?

json.loads(): If you have a JSON string, you can parse it by using the json.loads() method.json.loads() does not take the file path, but the file contents as a string, using fileobject.read() with json.loads() we can return the content of the file.


1 Answers

df = pd.read_json ("filename.json", lines = True)

like image 88
J_V Avatar answered Nov 14 '22 20:11

J_V