[英]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.