Description
I am trying to read a fixed width file using read_fwf function and coerce the column data types by using the 'converters' parameter. I created a dictionary that specifies a function that converts to the type that I desire for each of the columns in the data file.
The problem is that not all columns are getting set to the type I specify and it appears that any column for which the first few rows of the data set are blank will be inferred or defaulted and not coerced to the data type I explicitly specified in the dictionary passed via the converters parameter.
As a test, I tried to coerce all column types to a string by passing a dictionary that looked something like this:
type_dict = {0: conv_str, 1: conv_str, 2: conv_str ... (n-1): conv_str), where n = number of columns
and conv_str is a function that is defined as follows:
def conv_str(x):
return str(x)
As previously explained, in the resulting data frame, all columns get converted to type string as desired, with the exception of the columns that had blank values for the first few rows of the data set. Those columns that had blank values get defaulted to the 'float' data type.