In pandas, if I use series.apply()
to apply a function with an inner function definition, for example:
def square_times_two(x):
def square(y):
return y ** 2
return square(x) * 2
data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
df = pd.DataFrame.from_dict(data)
df["col_3"] = df.col_1.apply(square_times_two)
is the inner function redefined for each row? Would there be a performance impact to having many inner functions in a function applied to a large series?
numpy.random
, and usetimeit
or something similar. $\endgroup$