已编辑:
如果其他单元格上的值满足条件,我想替换一个单元格中的值
目前,我有这个
for a in ACPurchased:
aPos = self.model.grid.get_cell_list_contents(a.pos)
CustAC = [a for a in aPos if a.breed =='AC']
for b in CustAC:
AC_Data = [b.AC,b.Appliance,b.COP]
self.AC_DataPOS[self.AC_DataPOS['Category'].isin(AC_Data) &
self.AC_DataPOS['Appliance'].isin(AC_Data) &
self.AC_DataPOS['COP'].isin(AC_Data),
'Status'] = 'occupied'
并返回此错误:
File"/Users/widhadyah/Dropbox/MyPythonProject/ePSSMaterialModel/src/MaterialModel.py", line 275, in UpdateUsedMachineStatus
'Status'] = 'occupied'
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/frame.py", line 2419, in __setitem__
self._set_item(key, value)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/frame.py", line 2485, in _set_item
value = self._sanitize_column(key, value)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/frame.py", line 2684, in _sanitize_column
if broadcast and key in self.columns and value.ndim == 1:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/indexes/base.py", line 1393, in __contains__
hash(key)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/generic.py", line 831, in __hash__
' hashed'.format(self.__class__.__name__))
TypeError: 'Series' objects are mutable, thus they cannot be hashed
我尝试使用.iterrows()并仍然遇到相同的错误。 关于这个问题有什么建议吗?
提前谢谢
答案 0 :(得分:0)
我认为需要DataFrame.loc
,因为通过布尔掩码和选择列Status
进行链式过滤
self.AC_DataPOS.loc[self.AC_DataPOS['Category'].isin(AC_Data) &
self.AC_DataPOS['Appliance'].isin(AC_Data) &
self.AC_DataPOS['COP'].isin(AC_Data),
'Status'] = 'occupied'