Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43490

Re: CSV to matrix array

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <javier@codecoa.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'example:': 0.03; 'element': 0.07; 'puts': 0.07; 'skip:` 10': 0.07; 'url:github': 0.09; 'cc:addr:python-list': 0.11; '333': 0.16; 'csv': 0.16; 'lambda': 0.16; 'mylist': 0.16; 'numpy': 0.16; 'subject:CSV': 0.16; 'subject:array': 0.16; 'suggested,': 0.16; 'think?': 0.16; 'wrote:': 0.18; 'split': 0.19; '>>>': 0.22; 'import': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; '&gt;&gt;&gt;': 0.24; 'skip:` 20': 0.24; 'guys': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'this:': 0.26; 'header:In- Reply-To:1': 0.27; 'array': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; '13,': 0.31; 'file:': 0.31; 'url:python': 0.33; 'fri,': 0.33; 'position.': 0.33; 'could': 0.34; 'something': 0.35; 'convert': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'mobile:': 0.37; 'list': 0.37; 'pm,': 0.38; '12,': 0.39; 'url:mail': 0.40; 'how': 0.40; 'dave': 0.60; 'skip:\xc2 10': 0.60; 'details.': 0.61; 'pick': 0.64; 'ana': 0.84; 'miranda': 0.84; 'presumably': 0.84; 'angel': 0.91; '2013': 0.98
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:x-originating-ip:in-reply-to:references :date:message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=dcUyv7tVJnCuX1PpSjgxapwS0uAKwtH0P9LY0g7d0BI=; b=gs5ew7bN7+BXLuO66+NUQF65Chb83ZrG85B7H4coYlZN1IY23IBf7scaF7O2IvH+/L Qtry02jRbXjVubsgGzo9cj2JJY7wWSsPOxdC0Z0q1F1zLxl9g5ajdLvHRFMPTcGQDRx3 Oeouac41t0BLEA9nmZxKz5yvOtmcnmJMWM1ezKUDnc1q/JrJiDTBX3pN6FJNSotKK25J pPaaKbWHE6ai8syitRK8WLR89oj7VD2xPvS7XmdPl+OZKnYGTmCH+des0chbuYAteUQc rqMsq2JbEO1O71qmrbL91q79Q3w0rxUzkXxRDq8L6IyPuMxfGuscoKqi/kINcIDLe/Ll Pozg==
MIME-Version 1.0
X-Received by 10.60.15.71 with SMTP id v7mr384339oec.10.1365806724137; Fri, 12 Apr 2013 15:45:24 -0700 (PDT)
X-Originating-IP [187.163.11.168]
In-Reply-To <5168486E.9000009@davea.name>
References <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> <mailman.530.1365787506.3114.python-list@python.org> <eed71ec6-589c-4b10-a617-a8f5145642a6@googlegroups.com> <5168486E.9000009@davea.name>
Date Fri, 12 Apr 2013 17:45:24 -0500
Subject Re: CSV to matrix array
From Javier Miranda <javier@codecoa.com>
To Dave Angel <davea@davea.name>
Content-Type multipart/alternative; boundary=089e013cc14a9fdc7004da31a84f
X-Gm-Message-State ALoCoQkzzap91IeBHpsA50Ey5gfcBHMU3Krge9n6aXBoPHhIfKewtn0tcaZTQT8rCI2ttfU2QETP
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.541.1365806733.3114.python-list@python.org> (permalink)
Lines 147
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365806734 news.xs4all.nl 2642 [2001:888:2000:d::a6]:33370
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43490

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Keep the flattened data array others suggested, and then just split it like
this: *(replace `example_data`, `_array`, and `columns`)*

>>> example_data = range(15)

>>> split_array = lambda _array, colums: \

. . .        [_array[i:i + colums] for i in \

. . .                xrange(0, len(_array), colums)]

 >>> print split_array(example_data, 5)

[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]]

Gist <https://gist.github.com/anonymous/f9064e4c8790ae037ec6>

What do you guys think?


On Fri, Apr 12, 2013 at 12:46 PM, Dave Angel <davea@davea.name> wrote:

> On 04/12/2013 01:29 PM, Ana Dionísio wrote:
>
>> That only puts the data in one column, I wanted to separate it.
>>
>> For example:
>> data in csv file:
>>
>> 1 2 3 4 5
>> 7 8 9 10 11
>> a b c d e
>>
>> I wanted an array where I could pick an element in each position. In the
>> case above if I did print array[0][3] it would pick 4
>>
>>
> I know nothing about numpy.
>
> How about something like:
>     import csv
>     myreader = csv.reader(....)
>     mylist = list(myreader)
>
>
> Presumably you can fill in the details.  Anyway, I think this will give
> you a list of lists, and perhaps you can convert that to a numpy array, if
> you really need one of those.
>
>
> --
> DaveA
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>



-- 
Javier Miranda
Mobile: +52 333 129 20 70

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: CSV to matrix array Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-04-12 19:23 +0200
  Re: CSV to matrix array Ana Dionísio <anadionisio257@gmail.com> - 2013-04-12 10:29 -0700
    Re: CSV to matrix array Dave Angel <davea@davea.name> - 2013-04-12 13:46 -0400
    Re: CSV to matrix array Javier Miranda <javier@codecoa.com> - 2013-04-12 17:45 -0500
    Re: CSV to matrix array cantorp@gmail.com - 2013-04-13 10:06 -0700
    Re: CSV to matrix array cantorp@gmail.com - 2013-04-13 10:06 -0700
  Re: CSV to matrix array Ana Dionísio <anadionisio257@gmail.com> - 2013-04-12 10:29 -0700

csiph-web