|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
换电脑后,运行代码报错,什么原因?
PS C:\Users\admin\Desktop\python> & C:\Users\admin\AppData\Local\Programs\Python\Python314\python.exe c:/Users/admin/Desktop/python/台账代码.py
Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\internals\blocks.py", line 1115, in setitem
casted = np_can_hold_element(values.dtype, value)
File "C:\Users\admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\dtypes\cast.py", line 1792, in np_can_hold_element
raise LossySetitemError
pandas.errors.LossySetitemError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\admin\Desktop\python\台账代码.py", line 258, in <module>
last1_data.loc[(last1_data['产品名称'] == '机动') & (last1_data['比例'] == 0.04),'产品名称'] = '较强' #如果产品名称为机动并且比例是0.6,那么统计名称为较强
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py", line 938, in __setitem__
iloc._setitem_with_indexer(indexer, value, self.name)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py", line 1953, in _setitem_with_indexer
self._setitem_with_indexer_split_path(indexer, value, name)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py", line 2044, in _setitem_with_indexer_split_path
self._setitem_single_column(loc, value, pi)
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\indexing.py", line 2181, in _setitem_single_column
self.obj._mgr.column_setitem(loc, plane_indexer, value)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\internals\managers.py", line 1503, in column_setitem
new_mgr = col_mgr.setitem((idx,), value)
File "C:\Users\admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\internals\managers.py", line 604, in setitem
return self.apply("setitem", indexer=indexer, value=value)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\internals\managers.py", line 442, in apply
applied = getattr(b, f)(**kwargs)
File "C:\Users\admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\internals\blocks.py", line 1118, in setitem
nb = self.coerce_to_target_dtype(value, raise_on_upcast=True)
File "C:\Users\admin\AppData\Local\Programs\Python\Python314\Lib\site-packages\pandas\core\internals\blocks.py", line 468, in coerce_to_target_dtype
raise TypeError(f"Invalid value '{other}' for dtype '{self.values.dtype}'")
TypeError: Invalid value '较强' for dtype 'float64' |
|