我試圖創建一個if語句,如果支付類別列爲Expense
,那麼填充工具類型列爲Legal
。如果聲明重新映射值
但是,無論支付類別如何,它都會將包含Legal
的所有內容都標記爲Legal
。
test={"Pay Category":["Indemnity","Indemnity","Indemnity","Indemnity","Expense","Expense","Expense","Medical"],"Description of Payment":["Legal","Legal","Legal","Legal","Legal","Legal","Frog","Legal",]}
test=pd.DataFrame(test)
test["Tool Type"]=""
if (test["Pay Category"]=="Medical") is not False:
test["Tool Type"][test["Description of Payment"].str.contains("Pharmacy|Prescription|RX",case=False)]="Pharmacy"
if (test["Pay Category"]=='Expense') is not False:
test["Tool Type"][test["Description of Payment"].str.contains("Legal|Attorney|Court|Defense",case=False)]="Legal"
我的理解是,if (test["Pay Category"]=='Expense') is not False:
是一個布爾值,它要麼是True or False
,應該只有在標準「是不假」執行if語句滿足。我錯過了什麼?
布蘭登
搜索支付列的描述,這些關鍵詞在工具類型列中全部映射到Legal。 – Bjc51192