I am new to ML and pandas.
I was going through a jupyter file of a linear regression program. There I saw
dataframe.head()
dataframe.describe()
dataframe.shape
Why does the first two have parentheses () and shape doesn't?
I try to run dataframe.shape() and it give error TypeError: 'tuple' object is not callable.
Here's a link to the documentation but it didn't help: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.shape.html
dataframe.shape looks like a function and functions should have ().
How to know when a function will not have a ()
Classes can have attributes and methods, attributes are .word, while methods are .word(), or .word(arg1, arg2, etc.)
You won't know in advance whether something you want to call is a method or attribute, but you will if you read the documentation for that class. In that documentation, shape is listed under attributes not under methods, so you can infer from that classification how to use it (i.e. without parentheses). Here's the doc link for pandas dataframes: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html
Make a habit of reading the documentation and it will save you a lot of headache!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With