Scan CSV file and saving it into an array

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Apr 24 20:21:43 EDT 2013


On 25 April 2013 00:01, Ana Dionísio <anadionisio257 at gmail.com> wrote:
> Hello!
>
> I have this script that scans a csv file and if the value in the first column == 200 it saves that row into an array.
>
> The problem is, I need to save that row and the next 10 rows in that same array. What can I add to the script so it does that? I tried to do for row in len(10): but I get an error.
>
>
> p = csv.reader(open('file.csv'), delimiter=';')
> a=[0]*2881
> a = numpy.array(a, dtype=dict)

You shouldn't be using a numpy array for this; use a list instead. I
suggest that you have a go at the Python tutorial and avoid using
numpy until you are more confident with the basics of Python itself.

The tutorial (for Python 2) is here:
http://docs.python.org/2/tutorial/


Oscar



More information about the Python-list mailing list