I have a pandas dataframe column which contains the below json formats:
{"events": null, "game": "yes", "catch": "yes", "throw": null}
{"events": null, "game": "yes", "catch": "no", "throw": null}
print(df_merge['PDH_Value'].head().to_dict())
{0: '{"roth": null, "pretax": null, "catchup": "false", "aftertax": null}', 1: '{"roth": null, "pretax": "true", "catchup": "true", "aftertax": null}', 2: '', 3: '{"roth": null, "pretax": "true", "catchup": "true", "aftertax": null}', 4: '{"roth": "true", "pretax": "true", "catchup": "true", "aftertax": "true"}'}
I wanted to iterate and fetch only the catch value ie "yes","no" from the json and store it in the same dataframe column.
Desired output:
df_merge['PDH_Value']
true
false
Tried the code and getting the below error:
pd.json_normalize(df_merge['PDH_Value'].apply(json.loads))['catch']
raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
yesandnovalues.catchproperty but hascatchup. Is it ok?