-1
df.shape #we check the shape of dataset
(1338, 7)

While calling the above shape function, we did not use () but for most of the other function we use (). why is that?

df.info()# gives the info of the dataset 
Ruban
  • 125
  • 7
  • Can you give context as to what `df` is, and what `df.shape` and `df.info()` are? Are you sure that `df.shape` is not a variable rather than a function? See https://www.quora.com/What-is-the-difference-between-functions-and-variables-in-python-programming – 0liveradam8 Sep 05 '20 at 14:40
  • 1
    shape is a property - not a function. see https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.shape.htmlhttps://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.shape.html – Patrick Artner Sep 05 '20 at 14:40
  • 1
    it may actually be a property – Chris Sep 05 '20 at 14:41
  • I suggest to reopen the question and close it as a duplicate of https://stackoverflow.com/questions/46615919/why-does-head-need-and-shape-does-not. – DYZ Sep 05 '20 at 17:10

1 Answers1

5

pandas.DataFrame.shape is not a function, it's a property, as you can see here in the definition of shape:

    @property
    def shape(self) -> Tuple[int, int]:
        ...

A property is accessed (read and written) just as if it were a regular attribute of the object, so no parentheses are used.

Thomas
  • 174,939
  • 50
  • 355
  • 478