Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。
Pandas DatetimeIndex.ceil()
函數將數據調到指定頻率。該函數將目標頻率作為輸入。它返回一個新的DatetimeIndex對象。
用法: DatetimeIndex.ceil(freq)
參數:
freq:最高頻率指向索引。必須為固定頻率,例如“ S”(秒)而不是“ ME”(月末)
返回:DatetimeIndex或TimedeltaIndex具有相同類型的索引,或者Series具有相同索引的Series
範例1:采用DatetimeIndex.ceil()
函數將DatetimeIndex對象的數據設置為指定的頻率。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here 'S' represents secondly frequency
didx = pd.DatetimeIndex(start ='2000-01-15 08:00', freq ='S', periods = 4)
# Print the DatetimeIndex
print(didx)
輸出:
現在我們想將DatetimeIndex對象的第二個基於頻率的頻率設置為基於分鍾的頻率
# convert to the passed frequency
# 'T' represents minute based frequency
didx.ceil('T')
輸出:
正如我們在輸出中看到的那樣,該函數已返回DatetimeIndex對象的上限值。
範例2:采用DatetimeIndex.ceil()
函數將DatetimeIndex對象的數據設置為指定的頻率。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here 'T' represents minutely frequency
didx = pd.DatetimeIndex(start ='2018-11-15 09:45', freq ='T', periods = 5)
# Print the DatetimeIndex
print(didx)
輸出:
現在我們想將DatetimeIndex對象的基於分鍾的頻率改為基於小時的頻率
# ceil the given frequency
didx.ceil('H')
輸出:
正如我們在輸出中看到的,該函數將DatetimeIndex對象的值設置為所需的頻率。
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Timestamp.tz用法及代碼示例
- Python Pandas Series.str.contains()用法及代碼示例
- Python Pandas dataframe.std()用法及代碼示例
- Python Pandas Timestamp.dst用法及代碼示例
- Python Pandas dataframe.sem()用法及代碼示例
- Python Pandas DataFrame.ix[ ]用法及代碼示例
- Python Pandas.Categorical()用法及代碼示例
- Python Pandas.apply()用法及代碼示例
- Python Pandas TimedeltaIndex.contains用法及代碼示例
- Python Pandas Timestamp.now用法及代碼示例
- Python Pandas Series.str.pad()用法及代碼示例
- Python Pandas Series.take()用法及代碼示例
- Python Pandas dataframe.all()用法及代碼示例
- Python Pandas series.str.get()用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas DatetimeIndex.ceil()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。