我有以下型別的列的資料框。
EmployeeID Name DOB Age
12345 xyz 1998/26/03 25.0
56789 abc 2000/05/10 27.0
`dtypes EmployeeID: int64
Name: object DOB: datetime64[ns] Age: float64
我想從資料框中排除日期時間和物件型別列我在下面的代碼中嘗試過
Lst = list(df.columns)
for columnIndex, colName in enumerate(lst):
if(df[colName].dtypes != 'object' and df[colName].dtypes != np.datetime64):
print(df[colName])
但沒有得到預期的輸出。任何人都可以為此提出解決方案嗎?
uj5u.com熱心網友回復:
您可以select_dtypes在exclude模式下使用:
out = df.select_dtypes(exclude=(object, 'datetime'))
輸出:
EmployeeID Age
0 12345 25.0
1 56789 27.0
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/511900.html
上一篇:如何加快拆分一列以創建新列?
