Reputation: 29
I have a column in the dataframe on which I apply many functions. For example,
df[col_name] = df[col_name].apply(lambda x: fun1(x))
df[col_name] = df[col_name].apply(lambda x: fun2(x))
df[col_name] = df[col_name].apply(lambda x: fun3(x))
I have 10 functions that I apply to this column for preprocessing and cleaning. Is there a way where I can refactor this code or make the block of code small?
Upvotes: 0
Views: 49
Reputation: 10959
How about
def fun(x):
for f in (fun1, fun2, fun3):
x = f(x)
return x
df[col_name] = df[col_name].apply(fun)
Upvotes: 2