Issue
I have dataframe with following type of columns.
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
I want exclude datetime and object type column from dataframe I tried below code
Lst = list(df.columns)
for columnIndex, colName in enumerate(lst):
if(df[colName].dtypes != 'object' and df[colName].dtypes != np.datetime64):
print(df[colName])
But not getting expected output. Can anyone please suggest solution for this?
Solution
You can use select_dtypes
in exclude
mode:
out = df.select_dtypes(exclude=(object, 'datetime'))
output:
EmployeeID Age
0 12345 25.0
1 56789 27.0
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.