Let say we have a dataframe with the following format:
col1
{'overall_mean': '93.07', 'overall_median': '91.05'}
{}
{'overall_mean': '91.02', 'overall_median': '95.03'}
The original data is in json format. I want to extract some elements from each row and here is what I tried:
df['col1'].apply(lambda col: col['overall_mean'])
If we have that element in the dictionary, everything is fine but if we don't have, it complains and it make sense. Then I changed to this one:
df['col1'].apply(lambda col: None if len(col['overall_mean']) == 1 else col['overall_mean'])
and the reason to choose this conditions len(col['overall_mean']) == 1 was because that is the only condition that returns True. However it still cannot find those null value.
df['col1'].apply(lambda col: col['overall_mean'] if 'overall_mean' in col else None)