1. select_dtypes方法select_dtypes方法允许你按数据类型选择列。它接受一个数据类型或数据类型列表作为参数,返回一个包含满足指定数据类型的列的DataFrame。参数:include:指定要包含的数据类型。可以是一个数据类型字符串(如'number'、'object'、'datetime'等)或一个数据类型列表。exclude:指定要排除的数据类型。可...
data.select_dtypes(include=['object'], exclude=['float64']) include -- 符合类型 exclude -- 排除类型 可以单独使用参数,也可以结合使用,返回的是符合筛选后的数据框。 data.select_dtypes(include=['object']).columns 返回列名。 参数选择有: 数字:number、int、floatbuer:bool时间:datetime64 类别:catego...
根据数据类型选择特征 select_dtypes(include=['']/exclude=[]) In [21]: df.select_dtypes(include=['object']).columns.values Out[21]: array(['term', 'loan_status', 'int_rate', 'emp_length', 'home_ownership', 'verification_status', 'desc', 'purpose', 'title', 'zip_code', '...
在Python中,select_dtypes函数是pandas库中的一个函数,用于选择DataFrame中特定数据类型的列。可以使用该函数来筛选出DataFrame中某种或某几种数据类型的列。 例如,可以通过指定参数include或exclude来选择需要包含的数据类型或需要排除的数据类型。具体用法如下: # 选择整数类型列 df.select_dtypes(include='int') # ...
# 导入Pandas库 import pandas as pd # 创建一个示例DataFrame data = {'A': [1, 2, 3], 'B': [4.0, 5.0, 6.0], 'C': ['a', 'b', 'c']} df = pd.DataFrame(data) # 选择整数类型的列 int_columns = df.select_dtypes(include='int') print(int_columns) # 选择浮点类型的列 float...
import pandas as pd myDF = pd.DataFrame({'A':[1,2],'B':[1.0,2.0],'C':['a','b']}) print("【显示】myDF") print(myDF) print("【执行】myDF.select_dtypes(include=['int64'])") print(myDF.select_dtypes(include=['int64'])) ...
df.select_dtypes(include='bool') b 0 True 1 False 2 True 3 False 4 True 5 False 1. 2. 3. 4. 5. 6. 7. 8. df.select_dtypes(include=['float64']) c 0 1.0 1 2.0 2 1.0 3 2.0 4 1.0 5 2.0 1. 2. 3. 4. 5. 6. ...
select_dtypes(include=object).columns) # Index(['arr_col'], dtype='str') You can also use include="string" or exclude="string". Author fjossandon commented Oct 30, 2024 • edited Hi @rhshadrach, Sorry for the late reply, I couldn't reply sooner... That new string data type ...
newdf =df.select_dtypes(include='int64') Try it Yourself » Definition and Usage Theselect_dtypes()method returns a new DataFrame that includes/excludes columns of the specified dtype(s). Use theincludeparameter to specify the included columns, or use theexcludeparameter to specify which column...
select_dtypes(include=["number"]).sum() Out[27]: int 6 dtype: int64 ### Issue Description `numeric_only=True` includes boolean values, whereas `select_dtypes(include=["number"])` does not ### Expected Behavior If judging by the NumPy type hierarchy the latter is more correct https:/...