On Fri, May 20, 2011 at 8:22 AM, Olivier Delalleau <[email protected]> wrote: > StringIO(data_file_name) will not read your file, it will just allow you to > read the string data_file_name. You can probably just use > open(data_file_name) (and yes,you'll probably need to open it for each call > to genfromtxt). > Sorry my script didn't work, I definitely didn't expect it to work right > away, it was more to give you an idea of the kind of stuff you could do > manually. I'd expect it should be pretty straightforward to fix it. I > personally find it easier to write my own custom code to load such small > data files, rather than try to find the right parameters for an existing > function ;) (especially with mixed float / string dta). > > -=- Olivier > > 2011/5/19 Aradenatorix Veckhom Vacelaevus <[email protected]> >> >> Thanks both for your helping: >> I was checking the script fro Olivier but doesn't works yet, later I tried >> with the asciitable package but I also never could read any of my files >> (finally I decide create a single file for each case, it means to get 2 >> arrays for each domain). >> I was reading a while about how to import data with genfromtxt in Numpy, >> it was very interesting because I have a lot of options for import data, I >> can skip headers and footers, I can import selected columns and other stuff, >> so I wanna use it for import my columns in each case and later get an output >> in a text file, how can I get it? >> My idea is to make something like: >> #!/usr/bin/env python >> #-*- coding:utf-8 -*- >> import numpy as np >> from StringIO import StringIO >> np.genfromtxt(StringIO(data_file_name), autostrip=True, skip_header=2, >> usecols=(1, 2, 3)) >> np.genfromtxt(StringIO(data_file_name), autostrip=True, skip_header=2, >> usecols=(4, 5, 6)) >> >> np.genfromtxt(StringIO(data_file_name), autostrip=True, skip_header=2, >> usecols=(-1)) >> But I'm not sure how to use it, I have not experience importing that >> stuff, but also I don't know If I need to add a line at the beginning with >> data = StringIO(data_file_name) >> Could you help me once more? >> Regards: >> Aradnix >> _______________________________________________ >> NumPy-Discussion mailing list >> [email protected] >> http://mail.scipy.org/mailman/listinfo/numpy-discussion >>
I agree with Olivier that you need to write a special script for this type of file because it contains multiple tables. Most general purpose functions like genfromtxt assume a single 'array' but this will not work here because you have 10 (5 blocks of two arrays) in a single file. If you really need help then you really need to provide the actual file without any changes somewhere. Bruce _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
