在多个条件下使用Numpy"where",但如果条件失败,则不执行任何操作



如果你能用Jupyter Notebook帮我完成这项任务,我将不胜感激。

1 store = vat['Sum of VAT'].notnull()
2 store1 = vat['Comment'] == "VAT"
3 vat['Comment'] = np.where(vat['External name'] == 'GBTICJE','Reverse charge + IC',vat['Comment'] )

我使用代码3根据"外部名称"列中的字符串值"GBTICJE"提取"Comment"列的字符串值,如果不满足条件,则不覆盖"Comment("列中现有的字符串。

但是如何集成代码1&2转换为代码3?因此,我能够首先基于1&2,然后执行初始代码3?

有更好的方法吗?

以下是我的建议:

vat.loc[(vat['Sum of VAT'].notnull()) &
(vat['Comment'] == "VAT") &
(vat['External name'] == 'GBTICJE'), "Comment"] = 'Reverse charge + IC'

最新更新