A DataFrame can be constructed from many sources — a dict of lists, each key becoming a column, a list of dicts, each dict becoming a row, a NumPy array with separate column names, or by reading a file directly with functions like pd.read_csv(). Internally, each column is stored as its own Series, which is why different columns can have different dtypes even though the whole structure behaves as one unified table, and why selecting a column returns a Series while selecting a row, via .loc or .iloc, also returns a Series, just oriented across columns instead.
1Understanding pd.DataFrame()
A DataFrame can be constructed from many sources — a dict of lists, each key becoming a column, a list of dicts, each dict becoming a row, a NumPy array with separate column names, or by reading a file directly with functions like pd.read_csv(). Internally, each column is stored as its own Series, which is why different columns can have different dtypes even though the whole structure behaves as one unified table, and why selecting a column returns a Series while selecting a row, via .loc or .iloc, also returns a Series, just oriented across columns instead.
Building a DataFrame from a dict of lists is usually clearer than a list of dicts for structured, column-oriented data — pick whichever shape matches how your source data is naturally organized.
import pandas as pd
df = pd.DataFrame({"name": ["Alice", "Bob"], "age": [30, 25]})
print(df)2Practical Example
Here is a real-world application of pd.DataFrame() showing how it is used in production Pandas code.
import pandas as pd
records = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]
df = pd.DataFrame(records)
print(df.dtypes)3Best Practices
Follow these guidelines when working with pd.DataFrame():
1. Construct a DataFrame from whichever native shape matches your source data most directly, dict of lists for column-oriented data, list of dicts for row-oriented records, rather than always reshaping to one style
2. Prefer pd.read_csv()/read_json()/etc. over manually parsing a file and building a DataFrame by hand, for correctness and speed
3. Set meaningful column names and an appropriate index explicitly, rather than relying on default integer labels for either
Tip: Building a DataFrame from a dict of lists is usually clearer than a list of dicts for structured, column-oriented data — pick whichever shape matches how your source data is naturally organized.
import pandas as pd
df = pd.DataFrame({"name": ["Alice", "Bob"], "age": [30, 25]})
print(df)