S.V
S.V

Reputation: 2793

Fastest way to remove date part from pandas Timestamp

pandas Timestamp has an efficient way (i.e. normalize() method) to remove the time part leaving only date, e.g.

import pandas as pd
timeStamp = pd.to_datetime('2019-01-01 13:15:17')
print('date only:',timeStamp.normalize())

Is there any efficient (i.e. more efficient than timeStamp - timeStamp.normalize()) way to remove the date part from a timestamp?

Thank you for your help!

EDIT: Please, the result has to be of type pd.Timedelta.

Upvotes: 1

Views: 300

Answers (2)

ncica
ncica

Reputation: 7206

you can use .time() function:

import pandas as pd
timeStamp = pd.to_datetime('2019-01-01 13:15:17')
print('time only:',timeStamp.time())

output:

time only: 13:15:17

Upvotes: 0

moys
moys

Reputation: 8033

import pandas as pd
timeStamp = pd.to_datetime('2019-01-01 13:15:17').time()
print(timeStamp)

Upvotes: 1

Related Questions