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

Closed
mr-yoo opened this issue Feb 10, 2019 · 2 comments · Fixed by #25266
Closed

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

mr-yoo opened this issue Feb 10, 2019 · 2 comments · Fixed by #25266
Labels
Bug Regression Functionality that used to work in a prior pandas version Strings String extension data type and string data
Milestone

Comments

@mr-yoo
Copy link

mr-yoo 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)

print(pd.__version__)
print(df)
0.23.4
    one   two
0  1000  3000
1  2000  4000
0.24.1
     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
@PetitLepton
Copy link
Contributor

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)
0.23.4
   one  two
0  100  300
1  200  400
0.24.1
     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)

in managers.py?

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

@WillAyd
Copy link
Member

WillAyd 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

@WillAyd WillAyd added Bug Regression Functionality that used to work in a prior pandas version Strings String extension data type and string data labels Feb 11, 2019
@WillAyd WillAyd added this to the 0.24.2 milestone Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Regression Functionality that used to work in a prior pandas version Strings String extension data type and string data
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants