To return a new Timedelta floored to this resolution, use the timedelta.floor() method. For daily floored resolution, set the freq parameter to the value D.
At first, import the required libraries −
import pandas as pd
TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s. Create a Timedelta object
timedelta = pd.Timedelta('5 days 10 min 25 s')
Display the Timedelta
print("Timedelta...\n", timedelta)
Return the floored Timestamp with daily floored resolution
timedelta.floor(freq='D')
Example
Following is the code
import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # create a Timedelta object timedelta = pd.Timedelta('5 days 10 min 25 s') # display the Timedelta print("Timedelta...\n", timedelta) # return the floored Timestamp # with daily floored resolution res = timedelta.floor(freq='D') # display the floored Timestamp print("\nTimedelta (daily floored)...\n", res)
Output
This will produce the following code
Timedelta... 5 days 00:10:25 Timedelta (daily floored)... 5 days 00:00:00