pandas 1.4.2

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

For a DataFrame with a sorted DatetimeIndex, this function selects the last few rows based on a date offset.

Parameters

offset : str, DateOffset, dateutil.relativedelta

The offset length of the data that will be selected. For instance, '3D' will display all the rows having their index within the last 3 days.

Raises

TypeError

If the index is not a DatetimeIndex

Returns

Series or DataFrame

A subset of the caller.

Select final 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.

first

Select initial 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 last 3 days:

This example is valid syntax, but we were not able to check execution
>>> ts.last('3D')
            A
2018-04-13  3
2018-04-15  4

Notice the data for 3 last calendar days were returned, not the last 3 observed days in the dataset, and therefore data for 2018-04-11 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.first 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#8395
type: <class 'function'>
Commit: