A small, complete example of the issue

pd.read_csv dtype error when there is string "inf" in one column of the csv file.

part file detail: 31 1.159451e+261 32 8.804630e+291 33 1.355031e+293 34 2.288852e+303 35 inf 36 4.439159e+261 37 1.809108e+282 38 2.257864e+250 39 8.623610e+295 Name: FT64, dtype: float64

df = pd.read_csv(src_path+os.sep+file, dtype=float) : will be error

but when i use this code :+1: df = pd.read_csv(src_path+os.sep+file), the csv can be read in. and the element type is object(str). i can use df.astype(float) to convert the df.

i am just confusing why use read_csv(file, dtype=float) is not useful

Comment From: chris-b1

Please make this a reproducible example - the data you posted works fine - you probably some other identifier than 'inf' in your data.

from io import StringIO
data = """31 1.159451e+261
32 8.804630e+291
33 1.355031e+293
34 2.288852e+303
35 inf
36 4.439159e+261
37 1.809108e+282
38 2.257864e+250
39 8.623610e+295
"""
df = pd.read_csv(StringIO(data), header=None, sep=' ', dtype=float)

df
Out[34]: 
      0              1
0  31.0  1.159451e+261
1  32.0  8.804630e+291
2  33.0  1.355031e+293
3  34.0  2.288852e+303
4  35.0            inf
5  36.0  4.439159e+261
6  37.0  1.809108e+282
7  38.0  2.257864e+250
8  39.0  8.623610e+295

df.dtypes
Out[35]: 
0    float64
1    float64
dtype: object