Shreyas Kulkarni
Shreyas' Blog

Shreyas' Blog

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.

Shreyas Kulkarni
ยทOct 16, 2021ยท

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

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๐Ÿคž

ย 
Share this