The DataFrame: Rows and Columns
A DataFrame is a two-dimensional, table-like structure of labelled rows and columns — Pandas' core object, where every column is itself a Series and all columns share one common row index.
Learn The DataFrame: Rows and Columns in our free Pandas course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a…
Part of the free Pandas course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
If the Series is a single column, the DataFrame is the whole spreadsheet. This is the object you'll spend 95% of your Pandas time working with.
A DataFrame is a 2-dimensional table of data: it has labelled rows (the index) and labelled columns .
Build one from a dictionary of lists : keys are column names, each list is a column's values.
Four attributes tell you everything about a DataFrame's shape and structure:
Grab a single column with square brackets and the column name. The result is a Series — exactly the object from Lesson 2:
Because it's a Series, every Series trick still works: df["age"].mean() , df["age"] * 2 , boolean filtering, and more.
Lesson 3 complete — you understand the DataFrame!
You know a DataFrame is a 2-D table whose columns are Series, you can build one from a dict of lists, inspect its shape, columns, index, and dtypes, and pull out a single column as a Series.
🚀 Up next: Creating DataFrames — learn every way to build a DataFrame: from dicts, lists of dicts, lists of lists, and NumPy arrays.
Practice quiz
What is a pandas DataFrame?
- A one-dimensional labelled array
- A Python dictionary
- A two-dimensional table with labelled rows and columns
- A NumPy scalar
Answer: A two-dimensional table with labelled rows and columns. A DataFrame is a 2-D table of labelled rows and columns, like a spreadsheet.
What is each column of a DataFrame?
- A Series
- A list
- A dict
- A NumPy array with no index
Answer: A Series. Each column is a Series, and all columns share the same row index.
What does df['age'] return when 'age' is one column?
- A DataFrame
- A list
- A scalar
- A Series
Answer: A Series. Selecting a single column with square brackets returns a Series.
What does df.shape return?
- A list of column names
- A (rows, columns) tuple
- The number of rows only
- The dtypes
Answer: A (rows, columns) tuple. shape is a (rows, columns) tuple describing the table's size.
For a 3-row, 3-column DataFrame, what is df.shape?
- (3, 3)
- (9,)
- (3,)
- (1, 9)
Answer: (3, 3). Three rows and three columns gives the tuple (3, 3).
Which attribute lists the column names?
- df.index
- df.dtypes
- df.columns
- df.shape
Answer: df.columns. df.columns holds the column names; df.index holds the row labels.
Which attribute shows the data type of each column?
- df.shape
- df.dtypes
- df.columns
- df.values
Answer: df.dtypes. df.dtypes reports each column's dtype.
Why is df.shape written without parentheses?
- It is a method that takes no args
- Parentheses are optional
- It returns a function
- It is an attribute, not a method
Answer: It is an attribute, not a method. shape, columns, index, and dtypes are attributes — no parentheses.
Can different columns of one DataFrame hold different data types?
- No, all must match like a NumPy array
- Yes, each column can have its own dtype
- Only numeric types are allowed
- Only if they share an index
Answer: Yes, each column can have its own dtype. Unlike a NumPy array, each DataFrame column can hold a different dtype.
Because a selected column is a Series, which operation still works on df['age']?
- Nothing — Series have no methods
- Only printing
- age
Answer: age. It is a Series, so Series methods like .mean() and arithmetic still apply.