Pandalar read_csv
yöntemi ile basit bir boşluk ayrılmış dosyayı okumaya çalışıyorum. Ancak, pandalar benim dtype
argümanına uymuyor gibi görünüyor. Belki yanlış bir şekilde belirliyorum?pandas pandas.read_csv ile dtype float32 belirtme 0.10.1
Bu basit test vakasına, read_csv
numaralı telefon hattımı biraz karmaşık bir şekilde ayırdım. Aslında 'gerçek' senaryomda converters
argümanını kullanıyorum ama bunu basitlik için kaldırdım. Ben de numpy.int32
veya numpy.int64
bir dtype
ile bu kullanarak bu denedim
>>> 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')
:
Aşağıda benim ipython oturumdur. Bu seçimler bir istisna neden: pandalar otomatik bir tamsayı içine/dönüştürmek float değerleri kesecek denemez çünkü
AttributeError: 'NoneType' object has no attribute 'dtype'
Ben AttributeError
varsayıyorum nedir?
32 bit bir Python sürümü olan 32 bit makinede çalışıyorum.
# dont' use dtype converters explicity for the columns you care about
# they will be converted to float64 if possible, or object if they cannot
df = pd.read_csv('test.csv'.....)
#### this is optional and related to the issue you posted ####
# force anything that is not a numeric to nan
# columns are the list of columns that you are interesetd in
df[columns] = df[columns].convert_objects(convert_numeric=True)
# astype
df[columns] = df[columns].astype('float32')
see http://pandas.pydata.org/pandas-docs/dev/basics.html#object-conversion
Its not as efficient as doing it directly in read_csv (but that requires
Birlikte doğruladı: gerçekten float32 desteklemediği
>>> !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 Bu [github üzerinde bu konuda] (https://github.com/pydata/pandas/issues/2570) benzer düşünüyorum altında benim için iyi Yukarıdaki eserler ... –
@AndyHayden Haklı olduğunu düşünüyorum. 'AttributeError' sorunu, github sorununun sözünü ettiği şeydir. Ancak, diğer senaryonda değerler yüzer fakat pandalar float64 yerine float32 kullanmayı denediğimde "dtype" argümanına uymazlar. –