0

I have a data frame of about 100 rows all with different values that looks something like the following:

Data frame 1:

Index Values
0 Celery
1 Beetroot
2 Pineapple

I also have another data frame that looks something like this:

Data frame 2:

Index Values
0 Apple
1 Carrot
2 Pineapple
3 Celery
4 Beetroot

And want to modify all the values in Data frame 1 to 'Other' In data frame 2 like:

Index Values
0 Apple
1 Carrot
2 Other
3 Other
4 Other

I could do this individually for every value but there are too many, and am a bit stuck on how to turn this into a loop:

Modifying beetroot to 'Other'

data_frame2 = data_frame2.replace([Beetroot], 'Other')

monica
  • 27
  • 3
  • Use: `df2.loc[df2['Values'].isin(df1['Values']), 'Values'] = 'Other'` – mozway Nov 28 '22 at 10:01
  • @mozway - Can you change dupe because no match? – jezrael Nov 28 '22 at 10:10
  • @jezrael sure, but you should know (e.g., [you closed this one](https://stackoverflow.com/questions/69448007/replace-value-in-column-based-on-value-in-given-list)) – mozway Nov 28 '22 at 10:14

0 Answers0