我有一个用三列分隔的文件:第一列是整数,第二列看起来像浮点数,但不是,第三列是字符串。我试图用pandas.read_csv
将其直接加载到python中
In [149]: d = pandas.read_csv('resources/names/fos_names.csv', sep='#', header=None, names=['int_field', 'floatlike_field', 'str_field'])
In [150]: d
Out[150]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 1673 entries, 0 to 1672
Data columns:
int_field 1673 non-null values
floatlike_field 1673 non-null values
str_field 1673 non-null values
dtypes: float64(1), int64(1), object(1)
pandas
尝试智能化并自动将字段转换为有用的类型。问题是我实际上并不希望它这样做(如果我这样做了,我会使用converters
参数)。如何防止pandas
自动转换类型?
我认为您最好的办法是首先使用numpy作为记录数组读取数据。
我计划在即将到来的pandas 0.10文件解析器引擎大修中添加显式列数据类型。我不能百分之百的投入,但是随着新的基础设施的出现,它应该变得非常简单(http://wesmckinney.com/blog/?p=543)。
相关问题 更多 >
编程相关推荐