Skip to content

[FEATURE] Ability to pass regex module flags in DataFrame.replace while regex=True #32233

Open
@vishnu-dev

Description

@vishnu-dev

Code Sample

# For ignoring case, I have to explicitly change the regex
replace_map = {
    '[Q|q]uick[P|p]ay with [Z|z]elle payment to ': 'Payment to',
    '[Q|q]uick[P|p]ay with [Z|z]elle payment from ': 'Payment from'
}
df.replace({'title': replace_map}, regex=True, inplace=True)

Problem description

According to pandas docs for DataFrame.replace the replace has ability to take regex input, but doesn't have the ability to take in regex flags such as re.I or re.IGNORECASE for case insensitive search. Can we have a flags argument to take in regex module flags as input.

Expected Output

replace_map = {
    'QuickPay with Zelle payment to ': 'Payment to',
    'QuickPay with Zelle payment from ': 'Payment from'
}
# Can't we include flags as argument?
df.replace({'title': replace_map}, regex=True, inplace=True, flags=re.I) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementStringsString extension data type and string datareplacereplace method

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions