0
In [65]: import pandas as pd
In [66]: one = pd.Timestamp('2016-12-22 12:22:02.123456789')
In [67]: two = pd.Timestamp('2016-12-22 12:22:02.123456779')
In [68]: one - two
Out[68]: Timedelta('0 days 00:00:00.000000')

I only get microsecond precision here. How can I get the answer in nanoseconds? I must be missing something obvious here. I get nanos when I try the following:

In [69]: one.nanosecond
Out[69]: 789
In [70]: two.nanosecond
Out[70]: 779

But I'd really like to do proper subtraction in case I have bigger delta between the two timestamps.

Any advice is appreciated.

Ant Smith
  • 91
  • 1
  • 1
  • 7

1 Answers1

2

It's not truncating the nanoseconds. It's just not displaying all of it when you print it.

import pandas as pd
one = pd.Timestamp('2016-12-22 12:22:02.123456789')
two = pd.Timestamp('2016-12-22 12:22:02.123456779')
a = one-two
print a
print a.components
print a.nanoseconds

Output:

0 days 00:00:00.000000
Components(days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0, nanoseconds=10)
10
Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78
  • This works. Now, I wonder, if I had 1 micro and 10 nanos difference between the two, I would have to check the non-zero parts of Components in order to display them. It sounds more organic to be able to display 1010 nanoseconds instead. But, oh well. Thank you! I'll make it work. – Ant Smith Feb 05 '17 at 17:40