我试图用pandasread_csv
方法读取一个简单的空格分隔文件。然而,熊猫似乎没有遵守我的论点。也许我说的不对?
我已经将我对这个简单测试用例的read_csv
的稍微复杂的调用提炼出来。实际上,我在“真实”场景中使用了converters
参数,但为了简单起见,我删除了这个参数。
下面是我的ipython会话:
>>> cat test.out
a b
0.76398 0.81394
0.32136 0.91063
>>> import pandas
>>> import numpy
>>> x = pandas.read_csv('test.out', dtype={'a': numpy.float32}, delim_whitespace=True)
>>> x
a b
0 0.76398 0.81394
1 0.32136 0.91063
>>> x.a.dtype
dtype('float64')
我也试过用这个和dtype
的numpy.int32
或numpy.int64
一起使用。这些选择导致异常:
AttributeError: 'NoneType' object has no attribute 'dtype'
我假设AttributeError
是因为pandas不会自动尝试将浮点值转换/截断为整数?
我在一台32位机器上运行32位版本的Python。
>>> !uname -a
Linux ubuntu 3.0.0-13-generic #22-Ubuntu SMP Wed Nov 2 13:25:36 UTC 2011 i686 i686 i386 GNU/Linux
>>> import platform
>>> platform.architecture()
('32bit', 'ELF')
>>> pandas.__version__
'0.10.1'
在熊猫0.10.1的情况下,上面的方法对我来说很好
0.10.1不太支持float32
看这个http://pandas.pydata.org/pandas-docs/dev/whatsnew.html#dtype-specification
您可以在0.11中这样做:
我已经确认,使用0.11-dev,这确实有效(在32位和64位上,结果相同)
相关问题 更多 >
编程相关推荐