The Python Oracle

How to drop DataFrame columns based on dtype

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Switch On Looping

--

Chapters
00:00 How To Drop Dataframe Columns Based On Dtype
00:53 Accepted Answer Score 61
01:06 Thank you

--

Full question
https://stackoverflow.com/questions/4881...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #pandas

#avk47



ACCEPTED ANSWER

Score 61


You can use select_dtypes to exclude columns of a particular type.

import pandas as pd

df = pd.DataFrame({'x': ['a', 'b', 'c'], 'y': [1, 2, 3], 'z': ['d', 'e', 'f']})

df = df.select_dtypes(exclude=['object'])
print(df)