I'm trying to pass a DtaFrame or Series in Python to json format with to_json()
and re-read it with read_json()
, but it saves or retrieves it in the wrong format. The series that I try to convert is:
pmes['ADS']['Junio']['RentabilidadAcumulada']
and I enter the following order:
x=pmes['ADS']['Junio']['RentabilidadAcumulada'].to_json(orient='split')
When I try to read it again, it returns me:
pd.read_json(x)
and if I read it with:
pd.read_json(x,orient='split')
I get an error:
Traceback (most recent call last):
File "", line 1, in pd.read_json (x, orient = 'split')
File "C: \ Users \ User \ Anaconda3 \ lib \ site-packages \ pandas \ io \ json \ json.py", line 366, in read_json return json_reader.read ()
File "C: \ Users \ User \ Anaconda3 \ lib \ site-packages \ pandas \ io \ json \ json.py", line 467, in read obj = self._get_object_parser (self.data)
File "C: \ Users \ User \ Anaconda3 \ lib \ site-packages \ pandas \ io \ json \ json.py", line 484, in _get_object_parser obj = FrameParser (json, ** kwargs) .parse ()
File "C: \ Users \ User \ Anaconda3 \ lib \ site-packages \ pandas \ io \ json \ json.py", line 576, in parse self._parse_no_numpy ()
File "C: \ Users \ User \ Anaconda3 \ lib \ site-packages \ pandas \ io \ json \ json.py", line 799, in _parse_no_numpy self.check_keys_split (decoded)
File "C: \ Users \ User \ Anaconda3 \ lib \ site-packages \ pandas \ io \ json \ json.py", line 566, in check_keys_split .format (bad_keys = pprint_thing (bad_keys)))
ValueError: JSON data had unexpected key (s): name
Could someone help me to pass the Series to json format and get it back in the same format? Thank you very much