Creating DataFrames from List of Dictionaries (Row-oriented) in Pandas 2026

Data Manipulation Mar 18, 2026

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 direct
  • pd.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

Related Tutorials

Share:
Last updated: March 2026
Built-in Functions in Python 2026 str() in Python 2026: String Conversion + Modern Formatting & Best Practices memoryview with JAX in Python 2026: Zero-Copy NumPy → JAX Array Interop + Efficient ML Examples memoryview with TensorFlow in Python 2026: Zero-Copy NumPy → Tensor Interop + GPU Pinning & ML Examples memoryview with TensorFlow in Python 2026: Zero-Copy NumPy → Tensor Interop + ML Examples memoryview with NumPy & PyTorch in Python 2026: Zero-Copy Views, Efficient Slicing & ML Interop Examples memoryview with NumPy in Python 2026: Zero-Copy Views, Efficient Slicing & Real ML Examples memoryview() in Python 2026: Zero-Copy Magic for Large Binary Data + Real Examples import() in Python 2026: How It Works, Security Risks & Modern Alternatives (importlib) zip() in Python 2026: How to Use It, strict=True Behavior & Real-World Examples vars() in Python 2026: Accessing Object Namespace + Modern Introspection Patterns type() in Python 2026: Dynamic Type Inspection & Object Creation + Modern Patterns tuple() in Python 2026: Immutable Sequences + Modern Patterns & Best Practices super() in Python 2026: Method Resolution & Modern Inheritance Patterns sum() in Python 2026: Summing Iterables + Modern Numeric Patterns & Best Practices staticmethod() in Python 2026: Static Methods, Utility Functions & Modern Best Practices sorted() in Python 2026: Sorting Iterables + Modern Patterns & Best Practices slice() in Python 2026: Creating Slice Objects + Modern Patterns & Best Practices setattr() in Python 2026: Dynamic Attribute Setting + Modern Patterns & Safety set() in Python 2026: Mutable Sets Creation + Modern Patterns & Best Practices