I have a new datasat every months with a number of columns who can change.
I want to create a new column in a dataframe with a function like :
def calcul(**kwargs):
[...]
return result
I would create my column like that :
df['result'] = df.apply(lambda x: calcul(x['A1'], x['A2'], x['B1']), axis = 1)
But i can have this case too :
df['result'] = df.apply(lambda x: calcul(x['A1'], x['A2'], x['A3'], x['B1', x['B2']), axis = 1)
I try to create a liste of args depending of the data and enter the list with sys.stdout.write(), but it doesn't work
liste = ["x[\'A1\']", "x[\'A2\']", "x[\'B1\']"]
df['result'] = df.apply(lambda x: calcul(sys.stdout.write(", ".join(liste))), axis = 1)