Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Data Science by (17.6k points)

Is there a better way to determine whether a variable in Pandas and/or NumPy is numeric or not ?

I have a self defined dictionary with dtypes as keys and numeric / not as values.

1 Answer

0 votes
by (41.4k points)

You can use this below line of code to check whether a variable is numeric or not:

import pandas as pd

from pandas.api.types import is_string_dtype

from pandas.api.types import is_numeric_dtype

df = pd.DataFrame({'A': ['a', 'b', 'c'], 'B': [1.0, 2.0, 3.0]})


>>>> True


>>>> True

Browse Categories