Pandas json_normalize and null values in JSON

I agree with vozman, and filling empty {} dictionaries will solve the problem. However, I had the same problem for my project and I made a package to work around with this kind of DataFrames. check out flat-table, it uses json_normalize but also expands rows and columns.

import flat_table
df = pd.DataFrame(data)
flat_table.normalize(df)

This will output the following. Lists expanded to different rows and dictionary keys expanded to different columns.

   index name_x  age name_y   models
0      0   John   30   Ford   Fiesta
1      0   John   30   Ford    Focus
2      0   John   30   Ford  Mustang
3      1   John   30    NaN      NaN
4      2   John   30   Fiat      500
5      2   John   30   Fiat    Panda

You can fill cars with empty dicts to prevent this error

data['cars'] = data['cars'].apply(lambda x: {} if pd.isna(x) else x)