我正在尝试按部门分组,并将具有相应经度和纬度的列保留到部门内人口最多的城市。知道为什么这不起作用吗?
popDEP = pop.copy().groupby("dep", as_index=False)[["dep","lon","lat","total"]].agg({'total': ['max']})
Population ... Traceback (most recent call last):
File "maintrain.py", line 43, in <module>
popDEP = pop.copy().groupby("dep", as_index=False)[["dep","lon","lat","total"]].agg({'total': ['max']})
File "/home/ludo915/anaconda3/lib/python3.8/site-packages/pandas/core/groupby/generic.py", line 951, in aggregate
result, how = self._aggregate(func, *args, **kwargs)
File "/home/ludo915/anaconda3/lib/python3.8/site-packages/pandas/core/base.py", line 410, in _aggregate
result = _agg(arg, _agg_2dim)
File "/home/ludo915/anaconda3/lib/python3.8/site-packages/pandas/core/base.py", line 383, in _agg
result[fname] = func(fname, agg_how)
TypeError: _agg_2dim() takes 1 positional argument but 2 were given
答案 0 :(得分:0)
我认为您已经有一个名为“total”的列名,并且您再次尝试创建一个具有相同名称的列,即此处 agg({'total': ['max']}) 的 'total'。< /p>
所以更改列名。