Skip to content
Advertisement

remove special characters and string from df columns in python

Currently my column is of object type and I’m trying to convert it to type numeric. But it shows the error because of special characters and string contained in it.

error:

JavaScript

code:

JavaScript

So, I want to remove the special char and string from the columns that requires only number and col1 being one of it. Any suggested solution?

Advertisement

Answer

Using str.replace with regex pattern.

Ex:

JavaScript

Output:

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