[SciPy-User] calculate new values in csv using numpy
Marc Shivers
marc.shivers at gmail.com
Mon Jul 18 09:27:10 EDT 2011
Also, the genfromtxt function should have returned a numpy array,
rather than a list of tuples. table[:,2] will return a result if
table is a numpy array. I think the problem might be in your dtype
input. You can read about dtype objects here:
http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html
On Mon, Jul 18, 2011 at 9:19 AM, Zachary Pincus <zachary.pincus at yale.edu> wrote:
> The csv-reading code gives you a structured array as an output. You will want to read the documentation about structured arrays to get a better sense of how to use them:
> http://docs.scipy.org/doc/numpy/user/basics.rec.html
>
> For your task, you want:
> result = table['s1'] + table['s2']
>
> (Here's a suggestion for how to append the result back into a named column in the same structured array:
> http://mail.scipy.org/pipermail/numpy-discussion/2007-September/029357.html )
>
> I'm not sure if there are any good canned methods for saving record arrays to csv files directly. Probably someone can suggest something... I usually just loop through the array at that point, using ','.join(whatever) to build the individual lines.
>
> Zach
>
>
>
> On Jul 18, 2011, at 9:07 AM, Johannes Radinger wrote:
>
>> Thank you,
>>
>> I think that will be better for calculations to get a 2D array instead of a tuple/matrix combination?
>>
>> What is the prefered way to import the data from csv, to calculate a new column and to save again into a csv?
>>
>> /J
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
More information about the SciPy-User
mailing list