Skip to content
Advertisement

Python: Round decimal places after seconds in timestamp

I have this series:

JavaScript

Initially, I wanted to round to seconds by doing:

JavaScript

However, I am trying to merge this dataset to another of higher frequency. So I’d like to round the decimal places of the timestamp instead.

Example: 2021-06-15 16:23:04.388 would become 2021-06-15 16:23:04.380

How can I do this? to a timestamp?

Advertisement

Answer

If .388 should become .380 we can dt.floor to the nearest 10 ms with:

JavaScript

or

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement