温馨提示:本文翻译自stackoverflow.com,查看原文请点击:pandas - TypeError: copy() takes no keyword arguments in Python 3.x

pandas - Python 3.x提示错误:TypeError: copy() takes no keyword arguments

发布于 2020-03-31 23:19:34

在过去的几个月中,我一直在使用以下几行代码而不会出现问题:

a['Area Code']=a['mpan'].str[:2] a.groupby(a['Area Code']) a=a[a['Area Code'].astype(int)<=23]  data_list=a.groupby('Area Code')[['mpan']].apply(lambda g: list (map(tuple, g.values.tolist()))).to_dict() 

我突然从最后一行遇到以下错误:

TypeError: copy() takes no keyword arguments

“ a”是(23,2)数据帧,已通过称为“区域代码”的列进行分组(并由SQL查询填充)。“ data_list”将是使用“区域代码”列作为键的字典。我对为什么错误涉及copy()而又不在行中而感到困惑。

我对Python还是很陌生,并且获得了有关该特定行的帮助,因此不确定其本质。

Traceback (most recent call last):  File "C:\ProgramData\Anaconda3\lib\site-  packages\pandas\core\groupby\groupby.py", line 735, in apply result = self._python_apply_general(f)  File "C:\ProgramData\Anaconda3\lib\site-  packages\pandas\core\groupby\groupby.py", line 751, in _python_apply_general keys, values, mutated = self.grouper.apply(f, self._selected_obj, self.axis)  File "C:\ProgramData\Anaconda3\lib\site-  packages\pandas\core\groupby\ops.py", line 171, in apply result_values, mutated = splitter.fast_apply(f, group_keys)  File "C:\ProgramData\Anaconda3\lib\site-  packages\pandas\core\groupby\ops.py", line 925, in fast_apply return libreduction.apply_frame_axis0(sdata, f, names, starts, ends)  File "pandas\_libs\reduction.pyx", line 505, in  pandas._libs.reduction.apply_frame_axis0  TypeError: copy() takes no keyword arguments  During handling of the above exception, another exception occurred:  Traceback (most recent call last):  File "<ipython-input-31-84e07b1b1635>", line 1, in <module> a.groupby('Area Code')[['mpan']].apply(lambda g: list (map(tuple,  g.values.tolist()))).to_dict()  File "C:\ProgramData\Anaconda3\lib\site-  packages\pandas\core\groupby\groupby.py", line 746, in apply return self._python_apply_general(f)  File "C:\ProgramData\Anaconda3\lib\site-  packages\pandas\core\groupby\groupby.py", line 751, in _python_apply_general keys, values, mutated = self.grouper.apply(f, self._selected_obj, self.axis)  File "C:\ProgramData\Anaconda3\lib\site-  packages\pandas\core\groupby\ops.py", line 171, in apply result_values, mutated = splitter.fast_apply(f, group_keys)  File "C:\ProgramData\Anaconda3\lib\site-  packages\pandas\core\groupby\ops.py", line 925, in fast_apply return libreduction.apply_frame_axis0(sdata, f, names, starts, ends)  File "pandas\_libs\reduction.pyx", line 505, in  pandas._libs.reduction.apply_frame_axis0  TypeError: copy() takes no keyword arguments 

查看更多

提问者
Conor Howard
被浏览
132
agold 2020-02-06 18:30

更新:该问题已在Pandas 1.0.1中修复,您可以使用pip进行安装:

pip install pandas==1.0.1

这是一个已知问题(3144131456):

GroupBy.apply被抚养TypeError如果调用与返回列表功能(:问题:31441

这已在1.0.x中解决,您可以例如通过pip以下方式安装

pip install git+ssh://git@github.com/pandas-dev/pandas.git@1.0.x