Home > Software engineering >  To Iterate dataframe to check the unit and convert the units .TypeError: tuple indices must be integ
To Iterate dataframe to check the unit and convert the units .TypeError: tuple indices must be integ

Time:12-31

I am trying to check the unit in my dataset but gettingthis error, is anybody can help me , in this problem

df=pd.read_csv("/content/unit_checkv1.csv")

UNITS ={"G/HA":0.001,"ML/100KG":0.001}

for row in df.iterrows():
  unit_factor, unit_target = UNITS[row["DOSAGE_UNIT"]]
  if unit_factor:
    row["DOSAGE"] = (
    row["DOSAGE"] * unit_factor
    if row["DOSAGE"] is not None
    else None
  )
row["DOSAGE_UNIT"] = unit_target

CodePudding user response:

You can use Series.map instead your solution:

df['NEW'] = df["DOSAGE_UNIT"].map(UNITS) * df['DOSAGE']
  • Related