首页 > 解决方案 > add one more new column supplytypecheck, check if supply type IMPG that should be Y else N

问题描述

df["supplyType"]

0     TAX
1     TAX
2     TAX
3     TAX
4     TAX
5     TAX
6    IMPG
Name: SupplyType, dtype: object

Question is when supplyType is IMPG i should add a new column supplytypecheck with value "Y" for True else "Y" for false

i done it like

a =df["SupplyType"].index

for i in a:
    
    if (df["SupplyType"][i]) == "IMPG":
        df["supplytypecheck"] = "Y"
    else:
        df["supplytypecheck"] = "N"

It givens all df["supplytypecheck"] values as "Y" but "Y" should only be value for last index because it equals to IMPG all the upper values are equal to TAX.

Please help how to solve it

标签: pythonpandasdataframeseries

解决方案


推荐阅读