1

I'm trying to organize the columns in the dataframe based on datatype. I thought I'd do this by using pandas.loc to isolate datatypes of each column and then append them to each other to get one large organized dataset

import numpy as np
import pandas as pd
control = pd.read_csv(loan_path, chunksize=1000)
control = pd.concat(control, ignore_index=True)
int_columns= control.loc[:, control.dtypes==int]

I expect a new dataset with every row and only the columns that have integer datatypes. Instead I get the index of every row but 0 columns.

I know there are columns with integer datatypes. I've also tried looking for categories and floats and always get the same wrong result

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
minanmafi
  • 31
  • 1
  • 3
  • 2
    See https://stackoverflow.com/questions/21271581/selecting-pandas-columns-by-dtype – ALollz Jul 16 '19 at 17:36
  • try `control.loc[:,control.dtypes == np.int64]` make sure you call `import numpy as np` – Umar.H Jul 16 '19 at 17:39
  • 2
    Possible duplicate of [Selecting Pandas Columns by dtype](https://stackoverflow.com/questions/21271581/selecting-pandas-columns-by-dtype) – linamnt Jul 16 '19 at 17:42
  • 1
    `select_dtypes` is now the proper way. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.select_dtypes.html – Andy L. Jul 16 '19 at 17:43

0 Answers0