Why do some pandas commands end with parentheses (and others don't)?

Photo by Alex Chumak on Unsplash

Why do some pandas commands end with parentheses (and others don't)?

Disclaimer: basic python and pandas knowledge is required to understand.

Each Python object in pandas is either a DataFrame or DataSeries, so let's understand what difference between both of them.

DataFrame: is just a table having rows and columns (pandas.core.frame.DataFrame)

DataSeries: Each column in DataFrame is called as DataSeries (pandas.core.series.Series)

here's an example:


df.head()
df.describe()

df is any DataFrame in pandas

head(), describe() takes and parentheses

but let's look at the following commands

df.shape
df.dtypes

these commands don't take parentheses,

so when to use parentheses and when not to use them?

the simple reason behind it is they are data frame and to understand that in detail visualize methods as actions, descriptions as attributes

let's take the example of a random boy in the group named as sam,

# these are the actions called methods that require parentheses
sam.eat()
sam.talk()
# these are the descriptions that don't require parentheses

sam.weight
sam.height

in simple words, we can conclude that Actions(Methods) require parentheses, and Attribute(Descriptions) don't need any parentheses.

it's not a hard and fast rule, but the example makes sense.

Thanks for reading🤞