用法:
Series.first(offset)
根據日期偏移選擇時間序列數據的初始期間。
當有一個以日期為索引的 DataFrame 時,此函數可以根據日期偏移量選擇前幾行。
- offset:str、DateOffset 或 dateutil.relativedelta
將選擇的數據的偏移長度。例如,“1M”將顯示第一個月內具有索引的所有行。
- Series或DataFrame
調用者的子集。
- TypeError
如果索引不是
DatetimeIndex
參數:
返回:
拋出:
例子:
>>> i = pd.date_range('2018-04-09', periods=4, freq='2D') >>> ts = pd.DataFrame({'A':[1, 2, 3, 4]}, index=i) >>> ts A 2018-04-09 1 2018-04-11 2 2018-04-13 3 2018-04-15 4
獲取前 3 天的行:
>>> ts.first('3D') A 2018-04-09 1 2018-04-11 2
請注意,返回的是前 3 個日曆日的數據,而不是數據集中觀察到的前 3 天,因此未返回 2018-04-13 的數據。
相關用法
- Python pandas.Series.filter用法及代碼示例
- Python pandas.Series.fillna用法及代碼示例
- Python pandas.Series.floordiv用法及代碼示例
- Python pandas.Series.factorize用法及代碼示例
- Python pandas.Series.flags用法及代碼示例
- Python pandas.Series.add_prefix用法及代碼示例
- Python pandas.Series.map用法及代碼示例
- Python pandas.Series.max用法及代碼示例
- Python pandas.Series.str.isdecimal用法及代碼示例
- Python pandas.Series.str.get用法及代碼示例
- Python pandas.Series.to_csv用法及代碼示例
- Python pandas.Series.dt.day_name用法及代碼示例
- Python pandas.Series.sample用法及代碼示例
- Python pandas.Series.head用法及代碼示例
- Python pandas.Series.eq用法及代碼示例
- Python pandas.Series.plot.line用法及代碼示例
- Python pandas.Series.to_pickle用法及代碼示例
- Python pandas.Series.between_time用法及代碼示例
- Python pandas.Series.reindex_like用法及代碼示例
- Python pandas.Series.dt.is_year_end用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Series.first。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。