Pandas json_normalize produces confusing `KeyError` message?

后端 未结 3 594
北海茫月
北海茫月 2021-01-12 02:27

I\'m trying to convert a nested JSON to a Pandas dataframe. I\'ve been using json_normalize with success until I came across a certain JSON. I\'ve made a smalle

3条回答
  •  花落未央
    2021-01-12 02:58

    I had this same problem! This thread helped, especially parachute py's answer.

    I found a solution using:

    df.dropna(subset = *column(s) with nested data*)
    

    then saving the resultant df as a new json. Load the new json and now you'll be able to flatten the nested columns.

    There's probably a more efficient way to get around this, but my solution works.

    edit: forgot to mention, I tried using the *errors = 'ignore'* arg in json.normalize() and it didn't help.

提交回复
热议问题