Skip to content
Advertisement

How to rename values in column having a specific separation symbols?

Values in my DataFrame look like this:

JavaScript

I want to remove everything in values of id column after _numeric. So desired result must look like:

JavaScript

How to do that? I know that str.replace() can be used, but I don’t understand how to write regular expression part in it.

Advertisement

Answer

You can use regex(re.search) to find the first occurence of _ + digit and then you can solve the problem.

Code:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement