Pandas infer_freq(~)
方法返回一個字符串,指示給定 DatetimeIndex
或 TimedeltaIndex
的推斷頻率。
參數
1.index
| DatetimeIndex
或TimedeltaIndex
從中推斷頻率的索引。
2. warn
| boolean
| optional
如果無法推斷頻率,是否打印警告消息。經測試,這個參數似乎沒有任何作用.默認,warn=True
.
注意
此方法可能會引發以下錯誤:
-
如果索引的日期少於 3 個,則會拋出
ValueError
。 -
如果索引不是 datetime-like 類型,則拋出
TypeError
。
返回值
指示推斷頻率的字符串。
例子
基本用法
考慮以下 DatetimeIndex
:
idx = pd.DatetimeIndex(["2020-12-25","2020-12-27","2020-12-29"])
idx
DatetimeIndex(['2020-12-25', '2020-12-27', '2020-12-29'], dtype='datetime64[ns]', freq=None)
因為我們沒有在構造函數中顯式指定 freq
參數,所以最終得到 freq=None
。
推斷頻率:
pd.infer_freq(idx)
'2D'
這告訴我們推斷的頻率(偏移)是 2 天。
相關用法
- Python BeautifulSoup insert方法用法及代碼示例
- Python scipy integrate.trapz用法及代碼示例
- Python inspect.Parameter.replace用法及代碼示例
- Python inspect.Parameter.kind用法及代碼示例
- Python int轉exponential用法及代碼示例
- Python integer轉string用法及代碼示例
- Python inspect.Signature.from_callable用法及代碼示例
- Python Django index用法及代碼示例
- Python inspect.isasyncgenfunction用法及代碼示例
- Python scipy interpolate.CubicHermiteSpline.solve用法及代碼示例
- Python inspect.isawaitable用法及代碼示例
- Python scipy interpolate.CubicSpline.solve用法及代碼示例
- Python BeautifulSoup insert_after方法用法及代碼示例
- Python int.from_bytes用法及代碼示例
- Python scipy integrate.cumtrapz用法及代碼示例
- Python int構造函數用法及代碼示例
- Python NumPy insert方法用法及代碼示例
- Python inspect.BoundArguments.apply_defaults用法及代碼示例
- Python scipy interpolate.PchipInterpolator.solve用法及代碼示例
- Python int.bit_length用法及代碼示例
- Python input用法及代碼示例
- Python BeautifulSoup insert_before方法用法及代碼示例
- Python integer轉roman用法及代碼示例
- Python inspect.BoundArguments用法及代碼示例
- Python int.bit_count用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 Pandas | infer_freq method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。