为什么/ pandas 如何将方括号与.loc和.iloc一起使用? [英] Why/How does Pandas use square brackets with .loc and .iloc?
问题描述
所以.loc和.iloc不是您的典型函数.他们以某种方式使用[和]包围参数,以便与普通数组索引可比.但是,我从来没有在另一个库中看到过这一点(我可以想到,也许numpy就是我正在空白的东西),而且我不知道它在技术上是如何工作的/是在python代码中定义的.
So .loc and .iloc are not your typical functions. They somehow use [ and ] to surround the arguments so that it is comparable to normal array indexing. However, I have never seen this in another library (that I can think of, maybe numpy as something like this that I'm blanking on), and I have no idea how it technically works/is defined in the python code.
在这种情况下,方括号是否只是函数调用的语法糖?如果是这样,那么如何使一个任意函数使用方括号而不是括号呢?否则,它们的使用/定义熊猫有什么特别之处?
Are the brackets in this case just syntactic sugar for a function call? If so, how then would one make an arbitrary function use brackets instead of parenthesis? Otherwise, what is special about their use/defintion Pandas?
谢谢.
推荐答案
在表底下,它们都使用__setitem__
和__getitem__
函数.
Underneath the covers, both are using the __setitem__
and __getitem__
functions.
这篇关于为什么/ pandas 如何将方括号与.loc和.iloc一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!