get list of pandas dataframe columns based on data type

前端 未结 12 1372
后悔当初
后悔当初 2020-12-07 07:37

If I have a dataframe with the following columns:

1. NAME                                     object
2. On_Time                                      object
         


        
12条回答
  •  [愿得一人]
    2020-12-07 07:57

    If after 6 years you still have the issue, this should solve it :)

    cols = [c for c in df.columns if df[c].dtype in ['object', 'datetime64[ns]']]
    

提交回复
热议问题