I would like to perform a specific operation for every column of my DataFrame, specifically apply a given operation to all but the last column.
I have done this with google help and it works but seems quite creepy to me.
Can you help me to improve it?
d = {
'col1': [1, 2, 4, 7],
'col2': [3, 4, 9, 1],
'col3': [5, 2, 11, 4],
'col4': [True, True, False, True]
}
df = pd.DataFrame(data=d)
def do_nothing(x):
return x
def minor(x):
return x<2
def multi_func(functions):
def f(col):
return functions[col.name](col)
return f
result = df.apply(multi_func({'col1': minor, 'col2': minor,
'col3': minor, 'col4': do_nothing}))
Thank you all
2inminor()?