Karina Data Scientist

Python tip

APIs often dump nested JSON into CSV columns. You can't analsze it until you flatten it.

After you flatten it - you can analyse data by OS, version, or device.

What's happening:

json.loads → Converts string to Python dict
.apply(pd.Series) → Expands dict keys into columns
pd.concat() → Combines with original data

Pro tip - handle errors safely:


# Some rows might have invalid JSON
df_meta = df['metadata'].apply(
lambda x: json.loads(x) if pd.notna(x) else {}
).apply(pd.Series)

2 weeks ago | [YT] | 33