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?
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 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.
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.
df = pd.read_json ("filename.json", lines = True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With