Reputation: 2793
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
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
Reputation: 8033
import pandas as pd
timeStamp = pd.to_datetime('2019-01-01 13:15:17').time()
print(timeStamp)
Upvotes: 1