On Sun, Oct 4, 2020 at 8:39 AM Tim Williams <tjand...@gmail.com> wrote:
> > > On Fri, Oct 2, 2020 at 11:00 AM Shaozhong SHI <shishaozh...@gmail.com> > wrote: > >> Hello, >> >> I got a json response from an API and tried to use pandas to put data into >> a dataframe. >> >> However, I kept getting this ValueError: arrays must all be same length. >> >> Can anyone help? >> >> The following is the json text. Regards, Shao >> >> (snip json_text) > > >> import pandas as pd >> >> import json >> >> j = json.JSONDecoder().decode(req.text) ###req.json >> >> df = pd.DataFrame.from_dict(j) >> > > I copied json_text into a Jupyter notebook and got the same error trying > to convert this into a pandas DataFrame:When I tried to copy this into a > string, I got an error,, but without enclosing the paste in quotes, I got > the dictionary. > > (delete long response output) > for k in json_text.keys(): > if isinstance(json_text[k], list): > print(k, len(json_text[k])) > > relationships 0 > locationTypes 0 > regulatedActivities 2 > gacServiceTypes 1 > inspectionCategories 1 > specialisms 4 > inspectionAreas 0 > historicRatings 4 > reports 5 > > HTH,. > > This may also be more of a pandas issue. json.loads(json.dumps(json_text)) has a successful round-trip > -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- https://mail.python.org/mailman/listinfo/python-list