Open In App

Python | Pandas Timedelta.floor()

Improve
Improve
Like Article
Like
Save
Share
Report

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Timedelta is a subclass of datetime.timedelta, and behaves in a similar manner. It is the pandas equivalent of python’s datetime.timedelta and is interchangeable with it in most cases. Timedelta.floor() method in pandas.Timedelta is used to return new Timedelta floored to this resolution.

Syntax: Timedelta.floor()

Parameters:
freq : a freq string indicating the flooring resolution

Returns: new floored Timedelta.

Code #1:




# importing pandas as pd 
import pandas as pd 
import datetime
  
# Create the Timedelta object 
td = pd.Timedelta(5.05, unit ='s')
  
# Print the Timedelta object 
  
print(td.floor('S'))


Output:

 0 days 00:00:05

Code #2:




# importing pandas as pd 
import pandas as pd 
import datetime
  
# Create the Timedelta object 
td = pd.Timedelta(13.25, unit ='h')
  
# Print the Timedelta object 
  
print(td.floor('H'))


Output:

0 days 13:00:00

Code #3:




# importing pandas as pd 
import pandas as pd 
from datetime import datetime
  
# Create the Timedelta object 
td = pd.Timedelta('7 days 15 hours')
  
# Print the Timedelta object 
  
print(td.floor('D'))


Output:

7 days 00:00:00


Last Updated : 14 Jan, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads