Skip to content
Advertisement

Error while using str.contains for checking numeric values in a column using regex

I have a dataframe. I want to check if a particular column has numeric values or not using regex matching. When I use str.contains it shows an error like below. What is the correct way to check if all the values in a column have numeric values or not?

JavaScript

Advertisement

Answer

You can use

JavaScript

With .astype(str), you will be able to run a regex on the numeric column.

The .str.contains(r'[^0-9]', na=True) expression will find all values that contain at least one char that is not a digit (like dots or commas).

Advertisement