Chris90
Chris90

Reputation: 1998

Rounding output value

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

Answers (1)

Elias Gudmundsen
Elias Gudmundsen

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

Related Questions