我卡住了。我嘗試在 python 代碼中撰寫這個 excel 公式,但是在搜索和嘗試差異代碼之后,我無法得到解決方案。
= IF(AND(K2="inscrito_registro")*OR(L2<>"inscrito_registro")*OR($L2<>"no_necesario")*OR($L2<>""),"con carga","罪過”)
我在 python 中嘗試了這段代碼,但它不正確:
df['Carga']=np.where(df['Registration Status'] == "inscrito_registro" and np.where(df['Estado Cancelacion Cargas'] != "inscrito_registro","con carga","sin carga "))
我剛剛嘗試了這段代碼avodin來嘗試“或”,但它不正確。有什么建議嗎?
謝謝
uj5u.com熱心網友回復:
嘗試如下,你不需要第二個 np.where 在第一個
df['Carga']=np.where(
(df['Registration Status'] == "inscrito_registro") &
(df['Estado Cancelacion Cargas'] != "inscrito_registro"),
"con carga",
"sin carga")
使用 | 對于 OR 條件,您可能需要將 OR 條件放在括號中
df['Carga']=np.where(
(df['Registration Status'] == "inscrito_registro") &
((df['Estado Cancelacion Cargas'] != "inscrito_registro") |
(df['Estado Cancelacion Cargas'] != "no_necesario") |
(df['Estado Cancelacion Cargas'] != "")
),
"con carga", "sin carga")
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/510272.html
