0

I am trying to turn a float into an integer by rounding down to the nearest whole number. Normally, I use numpy's .apply(np.floor) on data in a dataframe and it works. However in this instance I am iterating in a forloop with this code:

f1.loc[today,'QuantityRounded'] = f1.loc[today,'QuantityNotRounded'].apply(np.floor)

And I get this error:

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

It seems when using a forloop and .loc the numpy function doesn't work.

What is the easiest way to round down in a forloop using .loc (sorry my vocabulary here is lacking)?

Thanks

Solomon Ucko
  • 5,724
  • 3
  • 24
  • 45
GC123
  • 323
  • 5
  • 15

1 Answers1

0

In this case, just use np.floor directly:

np.floor(f1.loc[today,'QuantityNotRounded'])
cs95
  • 379,657
  • 97
  • 704
  • 746
Solomon Ucko
  • 5,724
  • 3
  • 24
  • 45