DataFrame (Pandas)
A DataFrame is pandas' 2-D, size-mutable table of rows and columns, like a spreadsheet or SQL table in memory. Each column can hold a different data type and every row shares a common index.
Pandas
The DataFrame is the workhorse of pandas. You can think of it as a dictionary of Series objects that all share the same row index — columns line up by label, not by position, which is what makes joining and aligning data so painless. The two axes are the index (axis 0, the rows) and the columns (axis 1).
You create one from almost anything: a dictionary of lists, a list of dictionaries, a NumPy array, or a file via pd.read_csv. Because it is size-mutable you can add or drop columns at will, but most methods return a new DataFrame rather than changing the original in place, so you typically reassign or chain.
A common gotcha is that selecting a single column with df['col'] returns a Series, while df[['col']] (double brackets) returns a one-column DataFrame. Knowing which you have matters because Series and DataFrame have slightly different methods.
Syntax
pd.DataFrame(data, index=None, columns=None, dtype=None)Examples
Python
import pandas as pd
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
print(df)Output:
a b
0 1 3
1 2 4