Selecting Pandas Columns by dtype

后端 未结 9 2042
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 01:22

I was wondering if there is an elegant and shorthand way in Pandas DataFrames to select columns by data type (dtype). i.e. Select only int64 columns from a DataFrame.

<
9条回答
  •  既然无缘
    2020-11-29 01:36

    Optionally if you don't want to create a subset of the dataframe during the process, you can directly iterate through the column datatype.

    I haven't benchmarked the code below, assume it will be faster if you work on very large dataset.

    [col for col in df.columns.tolist() if df[col].dtype not in ['object','

提交回复
热议问题