0

I have a data frame df like below:

name     team
Peter     A
Mary      A
John      B

Now I want to update John's team from B to C. I could loop over the dataframe, find the row with name = 'John', delete it and add a new row. However, I am wondering is there a more elegant way to do this? Thanks!

Edamame
  • 23,718
  • 73
  • 186
  • 320

1 Answers1

1

Use loc:

df.loc[df['name'] == 'John', 'team'] = 'C'

The resulting output:

    name team
0  Peter    A
1   Mary    A
2   John    C
root
  • 32,715
  • 6
  • 74
  • 87