目 录
1、空值判断
判断数据是否为空值的常用函数有:pd.isna(),pd.isnull(),np.isnat()和np.isnan(),四种方法用于判断的数据类型如下表所示:

注意:
1、判断某个值是否空值,将该值传给相应函数即可,如pd.isna(input_data)、np.isnan(np.nan);
2、pd.isna 是pandas0.21版本引入的,能判别最大范围的空值;
3、对array、Serise或DataFrame运用相关函数时,结果也是相同形状的array、Serise或者DataFrame,例如:

2、其他数据类型判断
2.1 判断Serise或DataFrame中某一列的数据类型
此时,可以借助pd.api.types方法,使用方法例如:
pd.api.types.is_datetime64_any_dtype(Serise_1)
详细的方法列表如下:



2.2 利用np.issubdtype()判断Serise或DataFrame中某元素的类型
使用方法举例:
np.issubdtype(df['str'][0],np.string_) #True
np.issubdtype(df['int32'][0],np.int32) #True
np.issubdtype(df['float64'][0],np.number)#True

博客主要介绍Python中数据类型的判断方法。包括空值判断,如pd.isna()、pd.isnull()等函数的使用及适用数据类型;还介绍了其他数据类型判断,如借助pd.api.types判断Serise或DataFrame某列数据类型,利用np.issubdtype()判断某元素类型。
1365

被折叠的 条评论
为什么被折叠?



