Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 24 characters in body
Source Link
Ethan
  • 1.7k
  • 9
  • 24
  • 39

I have a table with 118000118,000 rows and 80 columns, and. I needwould like to select 8 columns from the table. I am reading the file using pandas' pd.read_csvthe pandas function pd.read_csv command as: df = pd.read_csv(filename, header=None, sep='|', usecols=[1,3,4,5,37,40,51,76]) I

df = pd.read_csv(filename, header=None, sep='|',
                 usecols=[1,3,4,5,37,40,51,76])

I would like to change the data type of each column inside of read_csvread_csv using dtype={'5': np.float, '37': np.float, ....})dtype={'5': np.float, '37': np.float, ....}, but this does not work.

There is a message that column 5 has mixed types. TheThe command print(df.dtypes)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 Is there a way of setting data types inside read_csvread_csv and what is the problem in this case? Many thanks!

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!

I have a table with 118,000 rows and 80 columns. I would like to select 8 columns from the table. I am reading the file using the pandas function 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 the 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?

Source Link
Liliana
  • 9
  • 1
  • 3

How to deal with errors of defining data types in pandas' read_csv ()?

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!