0

I want to replace multiple string 'abc' to 0 in Pandas using loop. Example as below.

lnequipmon  equipten    lnequipten  callcard    cardmon
3.38        126.10      4.84        1.00        14.25
4.00        1975.00     7.59        1.00        16.00
abc         0.00        abc         1.00        23.00
abc         0.00        abc         1.00        21.00
abc         0.00        abc         1.00        17.25
3.57        970.95      6.88        1.00        28.25
abc         0.00        abc         0.00        0.00
abc         0.00        abc         1.00        14.50
abc         0.00        abc         1.00        15.50
abc         0.00        abc         0.00        0.00
3.44        1568.35     7.36        1.00        19.00
abc         0.00        abc         0.00        0.00 

i have more then 500 such values and more than 100 columns. Please help me how to replace these 'abc' to 0 using loop or function

2
  • 2
    df = df.replace('abc',0) Commented Dec 10, 2018 at 14:53
  • df = df.mask(df.values == 'abc', 0) Maybe faster. Commented Dec 10, 2018 at 15:01

1 Answer 1

0

You use a simple replace function.

>>> s = pd.Series([0, 1, 2, 3, 4])
>>> s.replace(0, 5)
0    5
1    1
2    2
3    3
4    4

For more information you can check out the documentation

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.