[英]Is there a way to filter columns in Python using multiple data types in condition?
我正在尝试根据数字和分类数据类型过滤列,然后为每个回归问题创建单独的列表。
问题是我无法使用 .isin(['object','O'])
列列表:
制造商 157 非空对象
模型 157 非空对象
Sales_in_thousands 157 非空 float64
Four_year_resale_value 121 非空 float64
Vehicle_type 157 非空对象
Price_in_thousands 155 非空 float64
Engine_size 156 非空 float64
马力 156 非空 float64
轴距 156 非空 float64
宽度 156 非空 float64
latest_Launch 157 非空对象
Power_perf_factor 155 非空 float64
我想使用 .isin([]) 来做它,因为可以在列表中传递多个选项,但它不起作用
df.dtypes.loc[df.dtypes.isin(['object','O'])]
df.dtypes.loc[(df.dtypes == ('object')) | (df.dtypes == ('O'))]
制造商对象
模型对象
Vehicle_type 对象
最新_启动对象
select_dtypes有一个方便的辅助函数,可以准确地执行您要执行的操作
df.select_dtypes(include=['O'])
df.select_dtypes(exclude=['O'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.