[Tutor] import data (txt/csv) into list/array and manipulation

A.T.Hofkamp a.t.hofkamp at tue.nl
Thu Nov 20 13:47:29 CET 2008

trias wrote:
> Hi,
>  so for this part of the problem it goes a bit like this:
>  I have a CSV file (file1) that contains three columns, column one contains
> a unique ID type str,
> columns two and three contain start and stop coordinates type int. 
>   the other file (file2) contains two columns, column one contains a single
> coordinate type int and the second column contains a value type float.
>  What I would like to do is for example be able to grab the values from
> file2 that lies within range defind by the start,stop coordinates associated
> with an ID from file1.
>   But most importantly I would like to be able to grab say the values from
> file1 that are from range((start-300),start) for every single ID in file1, I
> guess plot them in an array and then calculate the sum/ of these values and
> plot them, ie for ob1 in file get values from range((1025-300),1025), for
> ob2((1090-300),1090) for ob3((2200-300),2200) and then plot/calculate the
> sum assuming the have the same start coordinate, so x axis would be (step)
> values from 0-300 and y axis would be the sum of values from ob1,2,3 for
> every single step value from 0-300.
>  does this make sense/

mostly, although you lost me when you started talking about ranges.

Computer programming is often about making small steps at a time (trying to do 
everything at the same time tends to make yourself get lost in what to do first).
In your case, I'd start with reading your first csv file (with the csv Python 
module) into memory. Once you have done that, get for example a list of 
start/stop coordinates from the loaded data.
Then start loading the second csv file, see how you can find a value, and then 
a range of values.

Once you have done that, you can implement you first objective.

After that start thinking about storing in arrays, plotting, etc.


More information about the Tutor mailing list