0

Given this list

a = [a,d]

Give a dataset as such

id type
a cat
b fish
c dog
d cat

If the id items of the dataset are found in the list a, then I need to change the related type item, if not leave the same type item

End result

id type
a bird
b fish
c dog
d bird

This code is not working

df["type"] = np.where(df["id"].isin(a), df["type"].replace("bird"), df["type"])
alz
  • 307
  • 2
  • 13

1 Answers1

1

Only set bird if match condition, replace is not necessary here if need set to same values:

df["type"] = np.where(df["id"].isin(a), "bird", df["type"])
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252