def first(self, offset):
if not isinstance(self.index, DatetimeIndex):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if len(self.index) == <NUM_LIT:0>:<EOL><INDENT>return self<EOL><DEDENT>offset = to_offset(offset)<EOL>end_date = end = self.index[<NUM_LIT:0>] + offset<EOL>if not offset.isAnchored() and hasattr(offset, '<STR_LIT>'):<EOL><INDENT>if end_date in self.index:<EOL><INDENT>end = self.index.searchsorted(end_date, side='<STR_LIT:left>')<EOL>return self.iloc[:end]<EOL><DEDENT><DEDENT>return self.loc[:end]<EOL>
Convenience method for subsetting initial periods of time series data
based on a date offset.

Parameters
----------
offset : string, DateOffset, dateutil.relativedelta

Returns
-------
subset : same type as caller

Raises
------
TypeError
    If the index is not  a :class:`DatetimeIndex`

See Also
--------
last : Select final periods of time series based on a date offset.
at_time : Select values at a particular time of the day.
between_time : Select values between particular times of the day.

Examples
--------
>>> 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

Get the rows for the first 3 days:

>>> ts.first('3D')
            A
2018-04-09  1
2018-04-11  2

Notice the data for 3 first calender days were returned, not the first
3 days observed in the dataset, and therefore data for 2018-04-13 was
not returned.