Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。
 Pandas  TimedeltaIndex.floor()函數將給定TimedeltaIndex對象中的所有值都設置為指定頻率。
用法: TimedeltaIndex.floor(freq)
參數:
freq:頻率字符串/對象
返回:相同類型的索引
範例1:采用TimedeltaIndex.floor()函數將給定的TimedeltaIndex對象中的所有值都設置為每日頻率。
# importing pandas as pd 
import pandas as pd 
  
# Create the TimedeltaIndex object 
tidx = pd.TimedeltaIndex(data =['3 days 06:05:01.000030', '1 days 06:05:01.000030', 
                               None, '1 days 02:00:00', '21 days 06:15:01.000030']) 
  
# Print the TimedeltaIndex object 
print(tidx)輸出:

現在我們將使用TimedeltaIndex.floor()函數將所有值取整。
# floor the values to daily frequency 
tidx.floor(freq ='D')輸出:

正如我們在輸出中看到的,TimedeltaIndex.floor()函數已將所有值下調至每日頻率。
範例2:采用TimedeltaIndex.floor()函數將給定TimedeltaIndex對象中的所有值都設置為每小時一次。
# importing pandas as pd 
import pandas as pd 
  
# Create the TimedeltaIndex object 
tidx = pd.TimedeltaIndex(data =['06:05:01.000030', '3 days 06:05:01.000030', 
                                '22 day 2 min 3us 10ns', '+23:59:59.999999', 
                                                  None, '+12:19:59.999999']) 
  
# Print the TimedeltaIndex object 
print(tidx)輸出:

現在我們將使用TimedeltaIndex.floor()函數將所有值取整。
# floor the values to hourly frequency 
tidx.floor('H')輸出:

正如我們在輸出中看到的,TimedeltaIndex.floor()函數已將所有值設置為小時頻率。
相關用法
- Python pandas.map()用法及代碼示例
 - Python Pandas Series.str.len()用法及代碼示例
 - Python Pandas.factorize()用法及代碼示例
 - Python Pandas TimedeltaIndex.name用法及代碼示例
 - Python Pandas dataframe.ne()用法及代碼示例
 - Python Pandas Series.between()用法及代碼示例
 - Python Pandas DataFrame.where()用法及代碼示例
 - Python Pandas Series.add()用法及代碼示例
 - Python Pandas.pivot_table()用法及代碼示例
 - Python Pandas Series.mod()用法及代碼示例
 - Python Pandas Dataframe.at[ ]用法及代碼示例
 - Python Pandas Dataframe.iat[ ]用法及代碼示例
 - Python Pandas.pivot()用法及代碼示例
 - Python Pandas dataframe.mul()用法及代碼示例
 - Python Pandas.melt()用法及代碼示例
 
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas TimedeltaIndex.floor。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
