pandas 1.4.2

ParametersRaisesReturnsBackRef
first(self: 'NDFrameT', offset) -> 'NDFrameT'

When having a DataFrame with dates as index, this function can select the first few rows based on a date offset.

Parameters

offset : str, DateOffset or dateutil.relativedelta

The offset length of the data that will be selected. For instance, '1M' will display all the rows having their index within the first month.

Raises

TypeError

If the index is not a DatetimeIndex

Returns

Series or DataFrame

A subset of the caller.

Select initial periods of time series data based on a date offset.

See Also

at_time

Select values at a particular time of the day.

between_time

Select values between particular times of the day.

last

Select final periods of time series based on a date offset.

Examples

This example is valid syntax, but we were not able to check execution
>>> 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:

This example is valid syntax, but we were not able to check execution
>>> ts.first('3D')
            A
2018-04-09  1
2018-04-11  2

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

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.generic.NDFrame.between_time pandas.core.generic.NDFrame.last pandas.core.generic.NDFrame.at_time pandas.core.generic.NDFrame.sort_values

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/generic.py#8322
type: <class 'function'>
Commit: