I have a table with 118000 rows and 80 columns, and I need to select 8 columns from the table. I am reading the file using pandas' pd.read_csv command as: df = pd.read_csv(filename, header=None, sep='|', usecols=[1,3,4,5,37,40,51,76]) I would like to change data type of each column inside of read_csv using dtype={'5': np.float, '37': np.float, ....}), but this does not work.
There is a message that column 5 has mixed types. The command print(df.dtypes) shows all columns of the type object. When I examine the column 5, I cannot see any problems. I have to change the data type for each column separately using pd.to_numeric. My question is: Is there a way of setting data types inside read_csv and what is the problem in this case? Many thanks!