Haraball.no

Create two or more new columns from a function applied to a pandas dataframe

2016-12-21

def calculate_something(row):
    """A function that returns two values"""
    return row[0] + row[1], row[0] - row[2]

df['new_col1'], df['new_col2'] = zip(*df.apply(calculate_something, axis=1))