[英]Prevent pandas.read_csv from inferring dtypes
How to prevent pandas.read_csv()
from inferring the data types. 如何防止
pandas.read_csv()
推断数据类型。 For example, its converting strings true
and false
to Bool: True
and False
. 例如,它将字符串
true
和false
转换为Bool: True
和False
。 The columns are many for many files, therefore not feasible to do: 许多文件的列很多,因此不可行:
df['field_name'] = df['field_name'].astype(np.float64)
for each of the columns in each file. df['field_name'] = df['field_name'].astype(np.float64)
用于每个文件中的每个列。 I prefer pandas to just read file as it is, no type inferring. 我更喜欢pandas只是读取文件,没有类型推断。
对于Pandas,请使用参数dtype=object
在加载时保持数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.