Skip to content

ENH: str.replace on multiple columns #31850

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

Closed
manel00 opened this issue Feb 10, 2020 · 3 comments
Closed

ENH: str.replace on multiple columns #31850

manel00 opened this issue Feb 10, 2020 · 3 comments
Labels
API Design Enhancement Strings String extension data type and string data

Comments

@manel00
Copy link

manel00 commented Feb 10, 2020

#IT WORKS
df['Total'] = df['Total'].str.replace(r'\.', '')
df['Homes'] = df['Homes'].str.replace(r'\.', '')
df['Dones'] = df['Dones'].str.replace(r'\.', '')

#IT DOESNT WORK
cols = ["Total", "Homes", "Dones"]
df[cols] = df[cols].str.replace(r'\.', '')

On Pandas 1.0.1

@WillAyd
Copy link
Member

WillAyd commented Feb 10, 2020

There is no .str accessor for data frame, only series. This is similar to #27581 but same comment applies - I'm not sure we really would want to add .str or .dt accessors to DataFrames anyway

@WillAyd WillAyd added API Design Needs Discussion Requires discussion from core team before further action labels Feb 10, 2020
@hirolau
Copy link

hirolau commented Feb 19, 2020

It is not too much hassle to do:

for col in ["Total", "Homes", "Dones"]:
    df[col] = df[col].str.replace(r'\.', '')

@simonjayhawkins simonjayhawkins changed the title Doesn't work replace multiple columns ENH: str.replace on multiple columns Apr 5, 2020
@simonjayhawkins simonjayhawkins added Enhancement Strings String extension data type and string data and removed Needs Discussion Requires discussion from core team before further action labels Apr 5, 2020
@mroeschke
Copy link
Member

Thanks for the suggestion but for a similar reason as #27581 there is hesitation to add accessors that operate on dataframe due to the nature of mixed dtypes. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Enhancement Strings String extension data type and string data
Projects
None yet
Development

No branches or pull requests

5 participants