› Forums › Python › Pandas (Python library) › Why df.shape Has No Parentheses in Pandas (Method vs Property Explained)
- This topic is empty.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
January 10, 2026 at 10:46 am #5934
—
❓ Question
df.shapein pandas has no parentheses. Is it a method?
✅ Short Answer
No.
df.shapeis not a method.
It is an attribute (also called a property) of a pandas DataFrame.
ߓ Understanding the Difference (Beginner-Friendly)
In Python, there is a clear distinction:
ߔ Methods
- Perform an action
- Require parentheses
() - May accept arguments
Example:
df.head() df.describe()ߔ Attributes / Properties
- Store or expose information
- Do NOT use parentheses
- Behave like variables
Example:
df.shape df.columns df.indexSo when you write:
df.shapeYou are accessing information, not calling a function.
ߓ What does
df.shapereturn?df.shapereturns a tuple:(number_of_rows, number_of_columns)Example
import pandas as pd df = pd.DataFrame({ "Name": ["Alice", "Bob", "Charlie"], "Age": [22, 25, 30] }) print(df.shape)Output
(3, 2)✔ 3 rows
✔ 2 columns
⚠️ Why parentheses don’t work
If you try:
df.shape()Python raises an error:
TypeError: 'tuple' object is not callableThis happens because:
df.shapealready returns a tuple- A tuple is not a function
- So it cannot be “called”
ߧ What’s happening internally (conceptual)
Internally,
shapeis defined as a property, something like:@property def shape(self): return (rows, columns)That’s why:
- No parentheses are needed
- No arguments can be passed
ߓ Common pandas examples (at a glance)
Expression Type Uses ()?df.shapeAttribute / Property ❌ No df.sizeAttribute ❌ No df.columnsAttribute ❌ No df.head()Method ✅ Yes df.describe()Method ✅ Yes
ߎ Final Takeaway (One-Line)
df.shapeis a property, not a method. It gives metadata (rows, columns), so parentheses are not needed.
-
AuthorPosts
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.

