0

Using the following as a simple example in pandas:

dataframe

        height  animal
1       33      dog
2       22      cat
3       1000    elephant
4       35      dog
.
.
1000    45      dog

how can i select all dog strings and set them to 0?

iv tried:

df['name'][df['name'] == 'dog'] = 0

but unfortunately is did not work

Zero
  • 74,117
  • 18
  • 147
  • 154
salty_coffee
  • 631
  • 1
  • 10
  • 22

2 Answers2

1

Just using replace

df.replace({'dog':0})

EDIT

df['animal'].replace('dog', 0)
BENY
  • 317,841
  • 20
  • 164
  • 234
0

Try this

df['animal'][df['animal'] == 'dog'] = 0
prudhvi Indana
  • 789
  • 7
  • 19