Elegant solution needed: Data manipulation

Mark Aristotle_00 at yahoo.com
Wed Jan 30 19:35:21 EST 2002


I have the following setup:

I have some data:

    height    weight    speed
1     3        6          12
2     5        9          20
3     4        10         15

I also have an equation:
add( speed , mul (weight, height) )

These both live in their own files.

I want to read in the equation and perform the corresponding
operations on the data.
So, for example, in this case, I'd have a new column "new":
    new
1    30
2    65
3    55

(hope the math is right).

I can certainly have the data set up as lists in a dictionary so that
data["height"] will give me [3, 5, 4].  I just need an elegant way to
parse the equation string and have it apply to the results.  It seems
pretty easy to convert from add ( x , y) to map( add, x , y) but 1) I
don't know python's regular expression stuff and 2) it seems there
should be an even easier way.  I definitely don't want to go as far as
formally parsing the equation to do this (unless python has some
killer built in tools).

Regards,
Mark



More information about the Python-list mailing list