Tim
Tim

Reputation: 119

Simple pandas Dataframe transformation

Venturing into python using some pandas. I'm trying to some very simple transformations on a Dataframe. Have read thru the docs and am not quite sussing out how this works. I want a simple subtraction on cells in a row. Want to return a new Dataframe with the computed column. Like so:

def geMeWhatIwant (data)
    #data is a Dataframe organized like index : col 1 : col2
    return log(data col1 - data col2)

It feels like this can be done under the hood without iterating over the Dataframe in my function. If I need to iterate then so be it. Could itterrows thru and do computations and append to return Dataframe. I'm simply looking for the most efficient and elegant way to do this in python - pandas

Thanks

Upvotes: 0

Views: 42

Answers (1)

LazyEval
LazyEval

Reputation: 859

This should work:

import numpy as np

np.log(df[col1] - df[col2])

Upvotes: 1

Related Questions