Selecting Pandas Columns by dtype

后端 未结 9 2002
爱一瞬间的悲伤
爱一瞬间的悲伤 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:54

    Multiple includes for selecting columns with list of types for example- float64 and int64

    df_numeric = df.select_dtypes(include=[np.float64,np.int64])
    
    0 讨论(0)
  • 2020-11-29 01:54

    You can use :

    for i in x.columns[x.dtypes == 'object']:   print(i)
    

    incase you just want to display only the column names of a particular dataframe rather than a sliced dataframe. Don't know if any function as such exits for python.

    PS : replace object with the datatype you want.

    0 讨论(0)
  • 2020-11-29 01:56

    select_dtypes(include=[np.int])

    0 讨论(0)
提交回复
热议问题