Reputation: 1998
How can I round my integer result when I apply my function?
am applying the function using,
df['value'] = df.apply(function_calc, axis=1)
Result for example in new column are 28.1,22.1
How can I use round function while I apply this function? Thanks!
Upvotes: 1
Views: 53
Reputation: 91
See: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.round_.html
import numpy as np
df['value'] = np.round(df.apply(function_calc, axis=1), decimals=0)
Using round inside function_calc will likely be significantly slower, as the np.round() is vectorized.
Upvotes: 1