round a column in dataframe

Question:

I have a dataframe ‘dayData’ and I am trying to round a zero decimal places one of the columns (the column is called ‘trace’)

I have tried using the following but with no success:

dayData["trace"] = dayData["trace"].round(0)

I get the exception:

AttributeError: 'numpy.float64' object has no attribute 'rint'

What is the correct syntax?

Asked By: Stacey

||

Answers:

With import numpy as np, do

dayData["trace"] = dayData["trace"].apply(np.round)
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.