Pandas: replace function syntax

I have a huge DataFrame with a column that has a list of names. Names have numbers and brackets attached to them. I try to remove them from their names. I found that a method that will work for this:

df.Name = df.Name.str.replace(r'[\(\)\d]+', '')

Can someone help me understand the syntax inside the replacement function?

(r'[\(\)\d]+', '')
+4
source share
1 answer

Can someone help me understand the syntax inside the replacement function?

What you see is a regular expression. Regular expressions have special syntax for specifying patterns.

In this regular expression, means a group of characters . Here the group of characters is filled in (open bracket), (closing bracket) and (numbers). [...]\(\)\d

+ " " , , . , '142(2' .

, , .

, regex101. , , . , , .

, , :

regular expression rendering

"", , , , , , .

+5

Source: https://habr.com/ru/post/1673787/


All Articles