简体   繁体   中英

What does the regex parameter in .replace() function mean

I was trying to replace a few unwanted strings that got scraped from a website. So I tried removing them using this code:

df["col_1"].replace('', '', regex=True, inplace=True)

What exactly do regex = True and inplace = True mean?

When inplace=True is passed, the data is renamed in place (it returns nothing), so you'd use:

df.some_column.operation(by=['some_col'], inplace=True)

When inplace=False is passed (this is the default value, so isn't necessary), performs the operation and returns a copy of the object, so you'd use:

df = df.some_column.operation(by=['some_col'])

So by default dataframes are immutable, inplace make them mutable.

And regex=True makes the replacing string be a regular expression

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM