← Back to Pandas Course | Chapter 3: DataFrame Basics | Lesson 2 of 7

DataFrame attributes (shape/dtypes/columns)

Attributes tell you the size, column names and data types of a DataFrame without printing all of it.
Syntax
python
df.shape
df.dtypes
df.columns
df.index

DataFrame attributes (shape/dtypes/columns)

shape gives (rows, columns), columns lists the column labels, index shows row labels, and dtypes reports each column's type. These are attributes, not methods, so no parentheses. values returns the underlying NumPy array.

Note: len(df) returns the number of rows.

Example: DataFrame attributes (shape/dtypes/columns)

python
import pandas as pd

df = pd.DataFrame({"name": ["Ann", "Bob"], "age": [28, 35], "score": [88.5, 92.0]})
print(df.shape)
print(list(df.columns))
print(df.dtypes)
print(len(df))

# Output:
# (2, 3)
# ['name', 'age', 'score']
# name      object
# age        int64
# score    float64
# dtype: object
# 2
Related Topics
Common Mistakes
  1. Calling shape() as a function
  2. Forgetting dtypes is plural
  3. Confusing len(df) with the number of columns
Chapter Summary
  • shape is (rows, cols)
  • columns lists the labels
  • dtypes shows types
  • They are attributes not methods
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.