How to add pandas pd.Timestamp
You can’t directly add Pandas pd.Timestamp
instances:
t1 = pd.Timestamp('now')
t2 = pd.Timestamp('now')
t1 + t2
# TypeError: unsupported operand type(s) for +: 'Timestamp' and 'Timestamp'
But you can convert them to a numpy
timestamp using their asm8
attribute, convert that timestamp to an integer, add it and convert it back:
t1 = pd.Timestamp('now')
t2 = pd.Timestamp('now')
tsum = (t1.asm8.astype(np.int64) + t2.asm8.astype(np.int64))
tsum_timestamp = pd.Timestamp(tsum.astype('<M8[ns]'))