目录
826、pandas.api.types.is_int64_dtype函数
827、pandas.api.types.is_integer_dtype函数
828、pandas.api.types.is_numeric_dtype函数
829、pandas.api.types.is_object_dtype函数
830、pandas.api.types.is_signed_integer_dtype函数
一、用法精讲
826、pandas.api.types.is_int64_dtype函数
826-1、语法
# 826、pandas.api.types.is_int64_dtype函数
pandas.api.types.is_int64_dtype(arr_or_dtype)
Check whether the provided array or dtype is of the int64 dtype.
Deprecated since version 2.1.0: is_int64_dtype is deprecated and will be removed in a future version. Use dtype == np.int64 instead.
Parameters:
arr_or_dtype
array-like or dtype
The array or dtype to check.
Returns:
boolean
Whether or not the array or dtype is of the int64 dtype.
Notes
Depending on system architecture, the return value of is_int64_dtype( int) will be True if the OS uses 64-bit integers and False if the OS uses 32-bit integers.
826-2、参数
826-2-1、arr_or_dtype(必须):可以是一个数组、索引、Series或者一个数据类型(dtype),该参数用于指定需要检测的数据。
826-3、功能
判断输入的内容是否为int64数据类型,在数据处理和分析过程中非常有用,尤其是在需要对数据类型进行验证和检查时。
826-4、返回值
返回一个布尔值:
- True: 如果arr_or_dtype是int64类型。
- False: 如果arr_or_dtype不是int64类型
826-5、说明
无
826-6、用法
826-6-1、数据准备
无
826-6-2、代码示例
# 826、pandas.api.types.is_int64_dtype函数
import pandas as pd
# 示例数组
data = pd.Series([1, 2, 3])
# 检查数据类型
is_int64 = pd.api.types.is_int64_dtype(data)
print(is_int64)
826-6-3、结果输出
# 826、pandas.api.types.is_int64_dtype函数
# True
827、pandas.api.types.is_integer_dtype函数
827-1、语法
# 827、pandas.api.types.is_integer_dtype函数
pandas.api.types.is_integer_dtype(arr_or_dtype)
Check whether the provided array or dtype is of an integer dtype.
Unlike in is_any_int_dtype, timedelta64 instances will return False.
The nullable Integer dtypes (e.g. pandas.Int64Dtype) are also considered as integer by this function.
Parameters:
arr_or_dtype
array-like or dtype
The array or dtype to check.
Returns:
boolean
Whether or not the array or dtype is of an integer dtype and not an instance of timedelta64.
827-2、参数
827-2-1、arr_or_dtype(必须):可以是一个数组、索引、Series或者一个数据类型(dtype),该参数用于指定需要检测的数据。
827-3、功能
检查输入的内容是否为整数类型,包括int8,int16,int32,int64等,它适用于各种数据分析和清洗场景,帮助用户识别数据类型。
827-4、返回值
返回一个布尔值:
- True: 如果arr_or_dtype是任何整数类型。
- False: 如果arr_or_dtype不是整数类型。
827-5、说明
无
827-6、用法
827-6-1、数据准备
无
827-6-2、代码示例
# 827、pandas.api.types.is_integer_dtype函数
import pandas as pd
# 示例数组
data_int = pd.Series([1, 2, 3])
data_float = pd.Series([1.0, 2.0, 3.0])
data_string = pd.Series(['1', '2', '3'])
# 检查数据类型
is_int = pd.api.types.is_integer_dtype(data_int)
is_float = pd.api.types.is_integer_dtype(data_float)
is_string = pd.api.types.is_integer_dtype(data_string)
print(is_int)
print(is_float)
print(is_string)
827-6-3、结果输出
# 827、pandas.api.types.is_integer_dtype函数
# True
# False
# False
828、pandas.api.types.is_numeric_dtype函数
828-1、语法
# 828、pandas.api.types.is_numeric_dtype函数
pandas.api.types.is_numeric_dtype(arr_or_dtype)
Check whether the provided array or dtype is of a numeric dtype.
Parameters:
arr_or_dtype
array-like or dtype
The array or dtype to check.
Returns:
boolean
Whether or not the array or dtype is of a numeric dtype.
828-2、参数
828-2-1、arr_or_dtype(必须):可以是一个数组、索引、Series或者一个数据类型(dtype),该参数用于指定需要检测的数据。
828-3、功能
检查给定的数组或数据类型是否是数值型的,如果是数值型,返回True,否则返回False。
828-4、返回值
返回一个布尔值,如果给定的数组或数据类型是数值型,返回True,否则返回False。
828-5、说明
无
828-6、用法
828-6-1、数据准备
无
828-6-2、代码示例
# 828、pandas.api.types.is_numeric_dtype函数
import pandas as pd
import numpy as np
# 使用数组
print(pd.api.types.is_numeric_dtype(np.array([1, 2, 3])))
print(pd.api.types.is_numeric_dtype(np.array(['a', 'b', 'c'])))
# 使用数据类型
print(pd.api.types.is_numeric_dtype(pd.Int64Dtype()))
print(pd.api.types.is_numeric_dtype(pd.StringDtype()))
828-6-3、结果输出
# 828、pandas.api.types.is_numeric_dtype函数
# True
# False
# True
# False
829、pandas.api.types.is_object_dtype函数
829-1、语法
# 829、pandas.api.types.is_object_dtype函数
pandas.api.types.is_object_dtype(arr_or_dtype)
Check whether an array-like or dtype is of the object dtype.
Parameters:
arr_or_dtype
array-like or dtype
The array-like or dtype to check.
Returns:
boolean
Whether or not the array-like or dtype is of the object dtype.
829-2、参数
829-2-1、arr_or_dtype(必须):可以是一个数组、索引、Series或者一个数据类型(dtype),该参数用于指定需要检测的数据。
829-3、功能
用于判断输入的数组或数据类型是否属于对象类型。例如,Pandas中的对象类型通常用于存储字符串或其他任何非数值数据。
829-4、返回值
返回一个布尔值,如果给定的数组或数据类型是对象类型,返回True,否则返回False。
829-5、说明
无
829-6、用法
829-6-1、数据准备
无
829-6-2、代码示例
# 829、pandas.api.types.is_object_dtype函数
import pandas as pd
import numpy as np
# 使用数组
print(pd.api.types.is_object_dtype(np.array(['a', 'b', 'c'])))
print(pd.api.types.is_object_dtype(np.array([1, 2, 3])))
# 使用数据类型
print(pd.api.types.is_object_dtype(pd.StringDtype()))
print(pd.api.types.is_object_dtype(pd.Int64Dtype()))
829-6-3、结果输出
# 829、pandas.api.types.is_object_dtype函数
# False
# False
# False
# False
830、pandas.api.types.is_signed_integer_dtype函数
830-1、语法
# 830、pandas.api.types.is_signed_integer_dtype函数
pandas.api.types.is_signed_integer_dtype(arr_or_dtype)
Check whether the provided array or dtype is of a signed integer dtype.
Unlike in is_any_int_dtype, timedelta64 instances will return False.
The nullable Integer dtypes (e.g. pandas.Int64Dtype) are also considered as integer by this function.
Parameters:
arr_or_dtype
array-like or dtype
The array or dtype to check.
Returns:
boolean
Whether or not the array or dtype is of a signed integer dtype and not an instance of timedelta64.
830-2、参数
830-2-1、arr_or_dtype(必须):可以是一个数组、索引、Series或者一个数据类型(dtype),该参数用于指定需要检测的数据。
830-3、功能
用于判断输入的数组或数据类型是否属于有符号整数类型。通常,有符号整数可以表示正数、负数和零,并且在数据分析中很常见。
830-4、返回值
返回一个布尔值,如果给定的数组或数据类型是有符号整数类型,返回True,否则返回False。
830-5、说明
无
830-6、用法
830-6-1、数据准备
无
830-6-2、代码示例
# 830、pandas.api.types.is_signed_integer_dtype函数
import pandas as pd
import numpy as np
# 使用数组
print(pd.api.types.is_signed_integer_dtype(np.array([-1, 0, 1])))
print(pd.api.types.is_signed_integer_dtype(np.array([1, 2, 3])))
print(pd.api.types.is_signed_integer_dtype(np.array([1.5, 2.5])))
# 使用数据类型
print(pd.api.types.is_signed_integer_dtype(pd.Int64Dtype()))
print(pd.api.types.is_signed_integer_dtype(pd.UInt64Dtype()))
print(pd.api.types.is_signed_integer_dtype(pd.Int32Dtype()))
830-6-3、结果输出
# 830、pandas.api.types.is_signed_integer_dtype函数
# True
# True
# False
# True
# False
# True