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
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