[Baypiggies] Question about python read data table from a text file

Yiou Li liyiou at gmail.com
Wed Apr 6 00:47:38 CEST 2011


Hi Alexandre,

I tried the following method and it seems the data is a long data
vector, not a data array as stored in the text file.

Best,
Leo


On Tue, Apr 5, 2011 at 3:42 PM, Alexandre Conrad
<alexandre.conrad at gmail.com> wrote:
> Is that what you want?
>
>>>> with open("data.txt") as f:
> ...     data = f.read().split()
> ...
>>>> data
> ['19', '19', '20', '21', '22', '17', '18', '19', '20', '21', '22',
> '23', '41', '42', '17', '18', '19', '20']
>
> ??
>
> 2011/4/5 Yiou Li <liyiou at gmail.com>:
>> Hi all,
>>
>> I have a text file with numerical data, like this:
>>
>> data.txt
>>
>> 19  19  20  21  22  17  18  19  20  21  22  23  41  42  17  18  19  20
>>  21  42  45  18  19  20  21  22  20  21  22  23  42  43  17  19  20
>> 21  22  23  24  40  41  42  43  44  45  46  47  16  17  18  19  20  21
>>  22  41  42  43  44  45  46  47  16  17  18  19  20  45  46  47  17
>> 18  19  20  41  42  43  44  45  20  21  22  23  40  41  42  43  44  45
>>  46  47  48  20  21  22  23  24  40  41  42  43  44  45  46  47  48
>> 17  18  19  ...
>>
>> Could you please refer me a python function to read this file into the
>> memory as a data table?
>>
>> the readlines() won't work because I need to access index the number
>> of ith row, jth column like x[i, j].
>>
>> Best,
>> Leo
>> _______________________________________________
>> Baypiggies mailing list
>> Baypiggies at python.org
>> To change your subscription options or unsubscribe:
>> http://mail.python.org/mailman/listinfo/baypiggies
>>
>
>
>
> --
> Alex | twitter.com/alexconrad
>


More information about the Baypiggies mailing list