pythonbeginner
Flatten Nested JSON with pandas
Use pd.json_normalize to flatten deeply nested API responses into a flat DataFrame.
pythonPress ⌘/Ctrl + Shift + C to copy
import pandas as pd
data = [
{'id':1,'user':{'name':'Alice','address':{'city':'NY','zip':'10001'}},'score':95},
{'id':2,'user':{'name':'Bob','address':{'city':'LA','zip':'90001'}},'score':87},
]
df = pd.json_normalize(data, sep='_')
print(df.columns.tolist())
print(df)Use Cases
- API response flattening
- JSON ETL
- nested data processing
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
pythonbeginner
Expand JSON Column into DataFrame Columns
Parse a JSON-string column and expand its keys into separate columns in one step.
Best for: JSON column expansion
#pandas#json
pythonintermediate
Read Large CSV in Chunks with Pandas
Process CSV files larger than RAM by reading in chunks — memory-efficient ETL pattern for data pipelines.
Best for: Processing multi-GB CSV files without running out of memory
#pandas#csv
pythonintermediate
Pandas Vectorised Operations vs Apply
Compare apply vs vectorised pandas operations for performance-critical column transformations.
Best for: feature engineering
#pandas#vectorization
pythonbeginner
SQLite + Pandas Local Data Pipeline
Run a lightweight local ETL with SQLite and pandas: load CSV, transform, persist to SQLite.
Best for: local analytics
#sqlite#pandas