I see there are a few ways to perform a method to an object. Either a.method(), method(a).
Here's an example,
import pandas as pd
data = {'AXP': 86.40, 'CSCO': '122.64', 'BA': '99.44'}
sindex = ['AXP', 'CSCO', 'BA', 'AAPL',]
aSer = pd.Series(data, index = sindex)
# Ex1: First way
> aSer.isnull()
AXP False
CSCO False
BA False
AAPL True
dtype: bool
# Ex2: Second way
> pd.isnull(aSer)
AXP False
CSCO False
BA False
AAPL True
dtype: bool
# Ex3: third way
> aSer.isnull
<bound method NDFrame.isnull of AXP 86.4
CSCO 122.64
BA 99.44
AAPL NaN
dtype: object>
# Ex4: function vs. method
aList = [3, 5, 2, 4]
sorted(aList) # object in function
aList.sort() # method
My understanding:
Ex1: "attaches" a method to the object.
Ex2: put the object inside a function. Are first two ways always equivalent?
Ex3: what is it doing here?
Ex4: Why aList.sorted()
won't work? sorted()
vs sort()
are from different package.
I am confused why so many things try to achieve the same thing, at the same time, not all of them will work.