Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace method with comma separator does not work in pandas 0.24.1 #25259

mr-yoo opened this issue Feb 10, 2019 · 2 comments


Copy link

commented Feb 10, 2019

The latest version (0.24.1) does not replace comma separator, but 0.23.4 does.

import pandas as pd

df = pd.DataFrame({'one': ["1,000", "2,000"], 'two': ["3,000", "4,000"]})
df = df.replace({',': ''}, regex=True)

    one   two
0  1000  3000
1  2000  4000
     one    two
0  1,000  3,000
1  2,000  4,000

If other characters are used with a comma, it works normally

df = df.replace({'1,': ''}, regex=True)
     one    two
0    000  3,000
1  2,000  4,000

This comment has been minimized.

Copy link

commented Feb 11, 2019

Hi, it is not related to commas. In your example @mr-yoo, if you try to replace ,0, it also fails. The replacement works only if the pattern is the beginning of the string

df.replace({',0': ''}, regex=True)
   one  two
0  100  300
1  200  400
     one    two
0  1, 000  3,000
1  2,000  4,000

Can it be related to

op = np.vectorize(lambda x: bool(re.match(b, x)) if isinstance(x, str)
                  else False)


re.match checks only if the beginning of the string matches. Should it be From my tests, it seems to reproduce the previous behaviour.


This comment has been minimized.

Copy link

commented Feb 11, 2019

@PetitLepton seems logical, so maybe introduced as part of #20656

Would certainly welcome a PR to fix if you are up for one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.