[英]Is there a way to filter columns in Python using multiple data types in condition?
I am trying to filter columns based on numeric and categorical data types and then create separate list for each for Regression Problems.我正在尝试根据数字和分类数据类型过滤列,然后为每个回归问题创建单独的列表。
Problem is i am not able to do this using .isin(['object','O'])问题是我无法使用 .isin(['object','O'])
List of Columns:列列表:
Manufacturer 157 non-null object制造商 157 非空对象
Model 157 non-null object模型 157 非空对象
Sales_in_thousands 157 non-null float64 Sales_in_thousands 157 非空 float64
four_year_resale_value 121 non-null float64 Four_year_resale_value 121 非空 float64
Vehicle_type 157 non-null object Vehicle_type 157 非空对象
Price_in_thousands 155 non-null float64 Price_in_thousands 155 非空 float64
Engine_size 156 non-null float64 Engine_size 156 非空 float64
Horsepower 156 non-null float64马力 156 非空 float64
Wheelbase 156 non-null float64轴距 156 非空 float64
Width 156 non-null float64宽度 156 非空 float64
Latest_Launch 157 non-null object latest_Launch 157 非空对象
Power_perf_factor 155 non-null float64 Power_perf_factor 155 非空 float64
I want to do it using .isin([]) as multiple options can be passed in the list but its not working我想使用 .isin([]) 来做它,因为可以在列表中传递多个选项,但它不起作用
df.dtypes.loc[df.dtypes.isin(['object','O'])]
df.dtypes.loc[(df.dtypes == ('object')) | (df.dtypes == ('O'))]
Manufacturer object制造商对象
Model object模型对象
Vehicle_type object Vehicle_type 对象
Latest_Launch object最新_启动对象
There's a handy helper function for exactly what you're trying to do, select_dtypes select_dtypes有一个方便的辅助函数,可以准确地执行您要执行的操作
df.select_dtypes(include=['O'])
df.select_dtypes(exclude=['O'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.