有没有更好的方法来判断 Pandas
中的变量是否和/或 NumPy
是 numeric
或不 ?
我有一个自定义 dictionary
与 dtypes
作为键和numeric
/not
作为值。
最佳答案
在 pandas 0.20.2
你可以这样做:
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]})
is_string_dtype(df['A'])
>>>> True
is_numeric_dtype(df['B'])
>>>> True
关于python - 如何确定 Pandas/NumPy 中的列/变量是否为数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19900202/