Creating DataFrames from List of Dictionaries (Row-oriented) in Pandas 2026
Creating a Pandas DataFrame from a list of dictionaries (where each dictionary represents a row) is one of the most common and intuitive ways to build tabular data in Python. This row-oriented approach is especially useful when working with JSON data, API responses, or when building records programmatically.
TL;DR — Two Main Ways
pd.DataFrame(list_of_dicts)– Simple and directpd.DataFrame.from_records(list_of_dicts)– Slightly more explicit
1. Basic Creation from List of Dictionaries
import pandas as pd
# List of dictionaries - each dict is one row
sales_records = [
{"order_id": 1001, "customer_id": 501, "amount": 1250.75, "region": "North", "order_date": "2026-03-15"},
{"order_id": 1002, "customer_id": 502, "amount": 890.50, "region": "South", "order_date": "2026-03-16"},
{"order_id": 1003, "customer_id": 503, "amount": 2340.00, "region": "East", "order_date": "2026-03-17"},
{"order_id": 1004, "customer_id": 501, "amount": 675.25, "region": "North", "order_date": "2026-03-18"}
]
df = pd.DataFrame(sales_records)
print(df)
print("\nData types:")
print(df.dtypes)
2. Converting Data Types After Creation
df = pd.DataFrame(sales_records)
# Optimize data types for better memory usage and performance
df = df.astype({
"order_id": "int32",
"customer_id": "int32",
"amount": "float32",
"region": "category"
})
# Convert date string to datetime
df["order_date"] = pd.to_datetime(df["order_date"])
print(df.dtypes)
3. Real-World Example: Processing API Response
# Simulating JSON API response
api_response = [
{"id": 1, "name": "Alice", "score": 95, "active": True},
{"id": 2, "name": "Bob", "score": 87, "active": False},
{"id": 3, "name": "Charlie", "score": 92, "active": True}
]
df = pd.DataFrame(api_response)
# Clean and optimize
df = df.astype({
"id": "int16",
"score": "int8",
"active": "bool"
})
print(df)
4. Best Practices in 2026
- Use
pd.DataFrame(list_of_dicts)— it's clean and readable - Immediately optimize dtypes after creation using
.astype() - Convert string dates to datetime with
pd.to_datetime() - Use
"category"dtype for columns with low cardinality (region, status, category, etc.) - Consider
pd.DataFrame.from_records()if you need more control over dtype inference
Row-Oriented Construction
A list of dictionaries is row-oriented: each dictionary is one record and its keys become column names. This matches JSON from APIs and rows built in a loop, so pd.DataFrame(records) is often the most natural constructor.
Keys missing from some records become NaN, and extra keys create new columns. Pass columns= to fix the order and pick only the fields you need.
Worked Example: Records from an API
Records with uneven keys are turned into a tidy DataFrame.
import pandas as pd
records = [
{"id": 1, "name": "Ana", "city": "Lisbon"},
{"id": 2, "name": "Ben"},
{"id": 3, "name": "Cara", "city": "Oslo", "vip": True},
]
df = pd.DataFrame(records)
print(df)
subset = pd.DataFrame(records, columns=["id", "city"])
print(subset)
nested = [{"id": 1, "address": {"zip": "1000"}}]
print(pd.json_normalize(nested))
Ben has no city and only Cara has vip, so those cells become missing. For nested dictionaries, pd.json_normalize flattens inner keys into columns like address.zip.
Practical Tips
Row-oriented data is common when you build records step by step, for example while parsing log lines or reading API pages. Collect the dictionaries in a Python list and create the DataFrame once at the end; this is much faster than adding rows to a DataFrame inside the loop. After construction, check df.dtypes, because values that arrived as strings in JSON may need converting with pd.to_numeric or pd.to_datetime before analysis.
If records come from several sources, normalise key names before building the DataFrame, for example by converting them to lower case with underscores. Otherwise Name and name become two different columns, each half empty.
Common Mistakes
- Expecting missing keys to raise an error.
- Appending rows one by one to a DataFrame in a loop.
- Passing nested dictionaries without json_normalize.
- Relying on key order for column order.
Quick Summary
- Each dictionary becomes one row.
- Missing keys become NaN.
- Use columns= to choose and order fields.
- Use json_normalize for nested data.
Conclusion
Creating DataFrames from a list of dictionaries is a very natural and commonly used pattern in Python data manipulation. In 2026, the best practice is to create the DataFrame first, then immediately optimize data types using .astype() and convert date columns properly. This row-oriented approach is especially useful when working with JSON data, APIs, or when building records dynamically.
Next steps:
- Try converting a list of dictionaries (from an API response or log file) into a well-typed Pandas DataFrame using the techniques above