I recently spent way too long debugging a piece of code, only to realize that the issue was I did not include a () after a command. What is the logic behind which commands require a () and which do not?
For example:
import pandas as pdcol1=['a','b','c','d','e']
col2=[1,2,3,4,5]df=pd.DataFrame(list(zip(col1,col2)),columns=['col1','col2'])df.columns
Returns Index(['col1', 'col2'], dtype='object')
as expected. If we use .columns()
we get an error.
Other commands it is the opposite:
df.isna()
Returns:
col1 col2
0 False False
1 False False
2 False False
3 False False
4 False False
but df.isna
returns:
<bound method DataFrame.isna of col1 col2
0 a 1
1 b 2
2 c 3
3 d 4
4 e 5>
Which, while not throwing an error, is clearly not what we're looking for.
What's the logic behind which commands use a () and which do not?
I use pandas as an example here, but I think this is relevant to python more generally.