如何确定 Pandas/NumPy 中的列/变量是否为数字?

2024-02-10

有没有更好的方法来确定变量是否在Pandas and/or NumPy is numeric或不 ?

我有一个自定义的dictionary with dtypes作为钥匙和numeric / not作为价值观。


In 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何确定 Pandas/NumPy 中的列/变量是否为数字? 的相关文章

随机推荐