I need to use a lambda function to do a row by row computation. For example create some dataframe
import pandas as pd
import numpy as np
def myfunc(x, y):
r
When you use df.apply()
, each row of your DataFrame will be passed to your lambda function as a pandas Series. The frame's columns will then be the index of the series and you can access values using series[label]
.
So this should work:
df['D'] = (df.apply(lambda x: myfunc(x[colNames[0]], x[colNames[1]]), axis=1))