Pandas: how to apply a transformation to each row?

pandas, python

Solution

I think you want something like:

def func(row):
    row.(here you can access any column of your dataframe) 

    return (the value in here will go to the 'NEW_COL' you are defining)

df['NEW_COL'] = df.apply(func,axis=1)

If you want something any more specific provide more details in your post

Problem

Initially I have a row and I would like to setup some new columns for each row following some non-trivial algorithm. I can do it that way: ``` for index, row in df.iterrows(): df.loc[df.index == index, 'NEW_COL'] = ... ``` but it is rather clumsy. Is there a way to befine lambda row -> row and apply it to the dataframe?

Original source