Я пытаюсь прочитать простой файл, разделенный пробелами, с помощью метода pandas read_csv
. Однако pandas, похоже, не подчиняется моему аргументу dtype
. Может быть, я неправильно указываю это?
Я пропустил свой сложный вызов 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 не будет автоматически пытаться преобразовать/усечь значения float в целое число?
Я работаю на 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'