You're getting this because genfromtxt
is returning a numpy record array, not a list
. It's just that when you print()
it to the console it looks like a list
.
from cStringIO import StringIO
raw = """01_500_aa_1000 990.0 990.0 112.5 0.2 72 0 0 1 0 0 0 0 0 0 0 0 0 1
02_500_aa_0950 990.0 990.0 112.5 0.2 77 0 0 1 0 0 0 0 0 0 0 0 0 1
03_500_aa_0600 990.0 990.0 112.5 0.18 84 0 0 1 0 0 0 0 0 0 0 0 0 1
04_500_aa_0700 990.0 990.0 112.5 0.18 84 0 0 1 0 0 0 0 0 0 0 0 0 1"""
sio = StringIO(raw)
data = genfromtxt(sio, dtype=None, unpack=False)
print data
print
print data.dtype
gives:
[ ('01_500_aa_1000', 990.0, 990.0, 112.5, 0.2, 72, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
('02_500_aa_0950', 990.0, 990.0, 112.5, 0.2, 77, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
('03_500_aa_0600', 990.0, 990.0, 112.5, 0.18, 84, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
('04_500_aa_0700', 990.0, 990.0, 112.5, 0.18, 84, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)]
[('f0', 'S14'), ('f1', '<f8'), ('f2', '<f8'), ('f3', '<f8'), ('f4', '<f8'), ('f5', '<i8'), ('f6', '<i8'), ('f7', '<i8'), ('f8', '<i8'), ('f9', '<i8'), ('f10', '<i8'), ('f11', '<i8'), ('f12', '<i8'), ('f13', '<i8'), ('f14', '<i8'), ('f15', '<i8'), ('f16', '<i8'), ('f17', '<i8'), ('f18', '<i8')]
unpack=True
and unpack=False
appear to return the same thing because you need a recarray
. I would suggest you try pandas
and forget about recarray
s altogether. You can pass a recarray
to the pandas.DataFrame
and actually get s*** done! For example,
df = DataFrame(data)
print df
print
print df.f0
yields:
f0 f1 f2 f3 f4 f5 f6 f7 f8 \
0 01_500_aa_1000 990.00 990.00 112.50 0.20 72 0 0 1
1 02_500_aa_0950 990.00 990.00 112.50 0.20 77 0 0 1
2 03_500_aa_0600 990.00 990.00 112.50 0.18 84 0 0 1
3 04_500_aa_0700 990.00 990.00 112.50 0.18 84 0 0 1
f9 f10 f11 f12 f13 f14 f15 f16 f17 f18
0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 1
2 0 0 0 0 0 0 0 0 0 1
3 0 0 0 0 0 0 0 0 0 1
0 01_500_aa_1000
1 02_500_aa_0950
2 03_500_aa_0600
3 04_500_aa_0700
Name: f0, dtype: object