-2

i was using Jupyter notebook to learn data analysing in Python and i recently came across two different answers because of a mistake i made and later wanted to know what is the difference between them.

The first one where i made a mistake

    sales['Unit_Cost'].median
    <bound method NDFrame._add_numeric_operations.<locals>.median of 0         45
1         45
2         45
3         45
4         45
          ..
113031    24
113032    24
113033    24
113034    24
113035    24
Name: Unit_Cost, Length: 113036, dtype: int64>

and the second one

sales['Unit_Cost'].median()
9

Basically i want to know the difference .median and .median()

This is my first time trying to code and im not a tech-savy person.English also is not my mother language so im sorry in advance if i made any grammar or coding errors or made a mistake in posting my question.

Thank you so much.

merv
  • 53,208
  • 11
  • 148
  • 196
  • 1
    Do you know what does it mean to call function or method? – buran May 11 '22 at 18:43
  • i sadly dont :( – beth blea May 11 '22 at 18:46
  • First case you have the representation of the function (an arbitrary string that gives the programmer an idea of what the function is), second one you have the actual output of the function. – mozway May 11 '22 at 18:46
  • 1
    In Python, objects (everything is an object) have attributes, which are accessed with that `dot` notation. One kind of attribute is a `method`. That's what `sales['Unit_Cost'].median` shows - the `median` method of that `sales[]` object. Methods (and functions) are run, or called, with `()` syntax. When called correctly they return some value, which is what you see in the 2nd use. – hpaulj May 11 '22 at 19:58

0 Answers0