这两行代码仅在传递的参数值上有所不同。我不清楚的是,为什么在第一种情况(“计数”)中需要引号,而在第二种情况(len)中不需要引号。
by_weekday1 = users.pivot_table(index='weekday', aggfunc='count')
by_weekday2 = users.pivot_table(index='weekday', aggfunc=len)
提前致谢!
您只能将Numpy或Pandas方法(换句话说,Pandas认为是内置[Pandas]的函数)指定为字符串(用引号引起来),否则它是一个函数(也可以是numpy函数):
users.pivot_table(index='weekday', aggfunc='sum')
类似于:
users.pivot_table(index='weekday', aggfunc=np.sum)
更新:
def _python_agg_general(self, func, *args, **kwargs):
func = self._is_builtin_func(func)
...
def _is_builtin_func(self, arg):
"""
if we define an builtin function for this argument, return it,
otherwise return the arg
"""
return SelectionMixin._builtin_table.get(arg, arg)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句