0

Here's a link to the Pandas documentation for this method: https://github.com/pandas-dev/pandas/blob/main/pandas/core/indexing.py#L271.

I've always understood that the syntax for wrapping paramaters of a function are parentheses brackets "()", however in Pandas there's a number of methods, such as .loc that you use square bracket.

How does the Pandas module achieve that? I can see loc is a method of the IndexingMixin class, but still a bit confused on why .loc isn't called with parentheses "()". Is the use of square bracket arbitrary, and could you assign any character to call the method?

Is there a link in the Python documentation somewhere that I can get more insight into?

Dylan
  • 9
  • 1
  • The quick answer is that using brackets on an object tells Python to call its `__getitem__` or `__setitem__` method. The `.loc` object has these methods defined appropriately with reference to its parent object. – Ben Grossmann Apr 13 '22 at 16:17

0 Answers0