-1

I want keep only 3 decimals of the value which I have in a column. But its not working properly.

Input Data

td['latitude']    
    2.999852
    2.999852
    2.714852
    4.998789
    4.999789

My code

dd = round(td['latitude'], 3)

Current Output

dd
3.0
3.0
2.714
5.0
5.0

Expected Output

dd
2.999
2.999
2.714
4.998
4.9997

What is wrong in my code. How to fix this.

aeapen
  • 871
  • 1
  • 14
  • 28
  • Refer below link. Think it will be useful. https://stackoverflow.com/questions/41383787/round-down-to-2-decimal-in-python – sre Nov 20 '19 at 04:36

1 Answers1

0

What is wrong in my code: round is round, i.e. returns the closest integer/precision round(1.66, 1) = 1.7.

How to fix this: I remembered some question/answer with truncate, but can't find them with a simple search. So here's a quick solution:

td['latitude'] // 0.001 * 0.001

Output:

0    2.999
1    2.999
2    2.714
3    4.998
4    4.999
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74