w3resource

Pandas DataFrame: asof() function

DataFrame - asof() function

The asof() function is used to get the last row(s) without any NaNs before where.

If there is no good value, NaN is returned for a Series or a Series of NaN values for a DataFrame

Syntax:

DataFrame.asof(self, where, subset=None)

Parameters:

Name Description Type/Default Value Required / Optional
where               Date(s) before which the last row(s) are returned. date or array-like of dates Required
subset  

For DataFrame, if not None, only use these columns to check for NaNs.

str or array-like of str
Default Value: None
Required

Returns: scalar, Series, or DataFrame
The return can be:

  • scalar : when self is a Series and where is a scalar
  • Series: when self is a Series and where is an array-like, or when self is a DataFrame and where is a scalar
  • DataFrame : when self is a DataFrame and where is an array-like
Return scalar, Series, or DataFrame.

Notes:

Dates are assumed to be sorted. Raises if this is not the case.

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - asfreq() function
Next: DataFrame - shift() function



Follow us on Facebook and Twitter for latest update.