Help on class Series in module pandas.core.series: class Series(pandas.core.base.IndexOpsMixin, pandas.core.generic.NDFrame) | Series(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False) | | One-dimensional ndarray with axis labels (including time series). | | Labels need not be unique but must be a hashable type. The object | supports both integer- and label-based indexing and provides a host of | methods for performing operations involving the index. Statistical | methods from ndarray have been overridden to automatically exclude | missing data (currently represented as NaN). | | Operations between Series (+, -, /, *, **) align values based on their | associated index values-- they need not be the same length. The result | index will be the sorted union of the two indexes. | | Parameters | ---------- | data : array-like, Iterable, dict, or scalar value | Contains data stored in Series. | | .. versionchanged:: 0.23.0 | If data is a dict, argument order is maintained for Python 3.6 | and later. | | index : array-like or Index (1d) | Values must be hashable and have the same length as `data`. | Non-unique index values are allowed. Will default to | RangeIndex (0, 1, 2, ..., n) if not provided. If both a dict and index | sequence are used, the index will override the keys found in the | dict. | dtype : str, numpy.dtype, or ExtensionDtype, optional | Data type for the output Series. If not specified, this will be | inferred from `data`. | See the :ref:`user guide <basics.dtypes>` for more usages. | name : str, optional | The name to give to the Series. | copy : bool, default False | Copy input data. | | Method resolution order: | Series | pandas.core.base.IndexOpsMixin | pandas.core.generic.NDFrame | pandas.core.base.PandasObject | pandas.core.accessor.DirNamesMixin | pandas.core.base.SelectionMixin | pandas.core.indexing.IndexingMixin | builtins.object | | Methods defined here: | | __add__(left, right) | | __and__(self, other) | | __array__(self, dtype=None) -> numpy.ndarray | Return the values as a NumPy array. | | Users should not call this directly. Rather, it is invoked by | :func:`numpy.array` and :func:`numpy.asarray`. | | Parameters | ---------- | dtype : str or numpy.dtype, optional | The dtype to use for the resulting NumPy array. By default, | the dtype is inferred from the data. | | Returns | ------- | numpy.ndarray | The values in the series converted to a :class:`numpy.ndarary` | with the specified `dtype`. | | See Also | -------- | array : Create a new array from data. | Series.array : Zero-copy view to the array backing the Series. | Series.to_numpy : Series method for similar behavior. | | Examples | -------- | >>> ser = pd.Series([1, 2, 3]) | >>> np.asarray(ser) | array([1, 2, 3]) | | For timezone-aware data, the timezones may be retained with | ``dtype='object'`` | | >>> tzser = pd.Series(pd.date_range('2000', periods=2, tz="CET")) | >>> np.asarray(tzser, dtype="object") | array([Timestamp('2000-01-01 00:00:00+0100', tz='CET', freq='D'), | Timestamp('2000-01-02 00:00:00+0100', tz='CET', freq='D')], | dtype=object) | | Or the values may be localized to UTC and the tzinfo discarded with | ``dtype='datetime64[ns]'`` | | >>> np.asarray(tzser, dtype="datetime64[ns]") # doctest: +ELLIPSIS | array(['1999-12-31T23:00:00.000000000', ...], | dtype='datetime64[ns]') | | __array_ufunc__(self, ufunc: Callable, method: str, *inputs: Any, **kwargs: Any) | | __div__ = __truediv__(left, right) | | __divmod__(left, right) | | __eq__(self, other) | | __float__(self) | | __floordiv__(left, right) | | __ge__(self, other) | | __getitem__(self, key) | | __gt__(self, other) | | __iadd__(self, other) | | __iand__(self, other) | | __ifloordiv__(self, other) | | __imod__(self, other) | | __imul__(self, other) | | __init__(self, data=None, index=None, dtype=None, name=None, copy=False, fastpath=False) | Initialize self. See help(type(self)) for accurate signature. | | __int__(self) | | __ior__(self, other) | | __ipow__(self, other) | | __isub__(self, other) | | __itruediv__(self, other) | | __ixor__(self, other) | | __le__(self, other) | | __len__(self) -> int | Return the length of the Series. | | __long__ = __int__(self) | | __lt__(self, other) | | __matmul__(self, other) | Matrix multiplication using binary `@` operator in Python>=3.5. | | __mod__(left, right) | | __mul__(left, right) | | __ne__(self, other) | | __or__(self, other) | | __pow__(left, right) | | __radd__(left, right) | | __rand__(self, other) | | __rdiv__ = __rtruediv__(left, right) | | __rdivmod__(left, right) | | __repr__(self) -> str | Return a string representation for a particular Series. | | __rfloordiv__(left, right) | | __rmatmul__(self, other) | Matrix multiplication using binary `@` operator in Python>=3.5. | | __rmod__(left, right) | | __rmul__(left, right) | | __ror__(self, other) | | __rpow__(left, right) | | __rsub__(left, right) | | __rtruediv__(left, right) | | __rxor__(self, other) | | __setitem__(self, key, value) | | __sub__(left, right) | | __truediv__(left, right) | | __xor__(self, other) | | add(self, other, level=None, fill_value=None, axis=0) | Return Addition of series and other, element-wise (binary operator `add`). | | Equivalent to ``series + other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.radd | | Examples | -------- | >>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd']) | >>> a | a 1.0 | b 1.0 | c 1.0 | d NaN | dtype: float64 | >>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e']) | >>> b | a 1.0 | b NaN | d 1.0 | e NaN | dtype: float64 | >>> a.add(b, fill_value=0) | a 2.0 | b 1.0 | c 1.0 | d 1.0 | e NaN | dtype: float64 | | agg = aggregate(self, func, axis=0, *args, **kwargs) | | aggregate(self, func, axis=0, *args, **kwargs) | Aggregate using one or more operations over the specified axis. | | .. versionadded:: 0.20.0 | | Parameters | ---------- | func : function, str, list or dict | Function to use for aggregating the data. If a function, must either | work when passed a Series or when passed to Series.apply. | | Accepted combinations are: | | - function | - string function name | - list of functions and/or function names, e.g. ``[np.sum, 'mean']`` | - dict of axis labels -> functions, function names or list of such. | axis : {0 or 'index'} | Parameter needed for compatibility with DataFrame. | *args | Positional arguments to pass to `func`. | **kwargs | Keyword arguments to pass to `func`. | | Returns | ------- | scalar, Series or DataFrame | | The return can be: | | * scalar : when Series.agg is called with single function | * Series : when DataFrame.agg is called with a single function | * DataFrame : when DataFrame.agg is called with several functions | | Return scalar, Series or DataFrame. | | See Also | -------- | Series.apply : Invoke function on a Series. | Series.transform : Transform function producing a Series with like indexes. | | Notes | ----- | `agg` is an alias for `aggregate`. Use the alias. | | A passed user-defined-function will be passed a Series for evaluation. | | Examples | -------- | >>> s = pd.Series([1, 2, 3, 4]) | >>> s | 0 1 | 1 2 | 2 3 | 3 4 | dtype: int64 | | >>> s.agg('min') | 1 | | >>> s.agg(['min', 'max']) | min 1 | max 4 | dtype: int64 | | align(self, other, join='outer', axis=None, level=None, copy=True, fill_value=None, method=None, limit=None, fill_axis=0, broadcast_axis=None) | Align two objects on their axes with the specified join method. | | Join method is specified for each axis Index. | | Parameters | ---------- | other : DataFrame or Series | join : {'outer', 'inner', 'left', 'right'}, default 'outer' | axis : allowed axis of the other object, default None | Align on index (0), columns (1), or both (None). | level : int or level name, default None | Broadcast across a level, matching Index values on the | passed MultiIndex level. | copy : bool, default True | Always returns new objects. If copy=False and no reindexing is | required then original objects are returned. | fill_value : scalar, default np.NaN | Value to use for missing values. Defaults to NaN, but can be any | "compatible" value. | method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None | Method to use for filling holes in reindexed Series: | | - pad / ffill: propagate last valid observation forward to next valid. | - backfill / bfill: use NEXT valid observation to fill gap. | | limit : int, default None | If method is specified, this is the maximum number of consecutive | NaN values to forward/backward fill. In other words, if there is | a gap with more than this number of consecutive NaNs, it will only | be partially filled. If method is not specified, this is the | maximum number of entries along the entire axis where NaNs will be | filled. Must be greater than 0 if not None. | fill_axis : {0 or 'index'}, default 0 | Filling axis, method and limit. | broadcast_axis : {0 or 'index'}, default None | Broadcast values along this axis, if aligning two objects of | different dimensions. | | Returns | ------- | (left, right) : (Series, type of other) | Aligned objects. | | all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs) | Return whether all elements are True, potentially over an axis. | | Returns True unless there at least one element within a series or | along a Dataframe axis that is False or equivalent (e.g. zero or | empty). | | Parameters | ---------- | axis : {0 or 'index', 1 or 'columns', None}, default 0 | Indicate which axis or axes should be reduced. | | * 0 / 'index' : reduce the index, return a Series whose index is the | original column labels. | * 1 / 'columns' : reduce the columns, return a Series whose index is the | original index. | * None : reduce all axes, return a scalar. | | bool_only : bool, default None | Include only boolean columns. If None, will attempt to use everything, | then use only boolean data. Not implemented for Series. | skipna : bool, default True | Exclude NA/null values. If the entire row/column is NA and skipna is | True, then the result will be True, as for an empty row/column. | If skipna is False, then NA are treated as True, because these are not | equal to zero. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | **kwargs : any, default None | Additional keywords have no effect but might be accepted for | compatibility with NumPy. | | Returns | ------- | scalar or Series | If level is specified, then, Series is returned; otherwise, scalar | is returned. | | See Also | -------- | Series.all : Return True if all elements are True. | DataFrame.any : Return True if one (or more) elements are True. | | Examples | -------- | **Series** | | >>> pd.Series([True, True]).all() | True | >>> pd.Series([True, False]).all() | False | >>> pd.Series([]).all() | True | >>> pd.Series([np.nan]).all() | True | >>> pd.Series([np.nan]).all(skipna=False) | True | | **DataFrames** | | Create a dataframe from a dictionary. | | >>> df = pd.DataFrame({'col1': [True, True], 'col2': [True, False]}) | >>> df | col1 col2 | 0 True True | 1 True False | | Default behaviour checks if column-wise values all return True. | | >>> df.all() | col1 True | col2 False | dtype: bool | | Specify ``axis='columns'`` to check if row-wise values all return True. | | >>> df.all(axis='columns') | 0 True | 1 False | dtype: bool | | Or ``axis=None`` for whether every value is True. | | >>> df.all(axis=None) | False | | any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs) | Return whether any element is True, potentially over an axis. | | Returns False unless there at least one element within a series or | along a Dataframe axis that is True or equivalent (e.g. non-zero or | non-empty). | | Parameters | ---------- | axis : {0 or 'index', 1 or 'columns', None}, default 0 | Indicate which axis or axes should be reduced. | | * 0 / 'index' : reduce the index, return a Series whose index is the | original column labels. | * 1 / 'columns' : reduce the columns, return a Series whose index is the | original index. | * None : reduce all axes, return a scalar. | | bool_only : bool, default None | Include only boolean columns. If None, will attempt to use everything, | then use only boolean data. Not implemented for Series. | skipna : bool, default True | Exclude NA/null values. If the entire row/column is NA and skipna is | True, then the result will be False, as for an empty row/column. | If skipna is False, then NA are treated as True, because these are not | equal to zero. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | **kwargs : any, default None | Additional keywords have no effect but might be accepted for | compatibility with NumPy. | | Returns | ------- | scalar or Series | If level is specified, then, Series is returned; otherwise, scalar | is returned. | | See Also | -------- | numpy.any : Numpy version of this method. | Series.any : Return whether any element is True. | Series.all : Return whether all elements are True. | DataFrame.any : Return whether any element is True over requested axis. | DataFrame.all : Return whether all elements are True over requested axis. | | Examples | -------- | **Series** | | For Series input, the output is a scalar indicating whether any element | is True. | | >>> pd.Series([False, False]).any() | False | >>> pd.Series([True, False]).any() | True | >>> pd.Series([]).any() | False | >>> pd.Series([np.nan]).any() | False | >>> pd.Series([np.nan]).any(skipna=False) | True | | **DataFrame** | | Whether each column contains at least one True element (the default). | | >>> df = pd.DataFrame({"A": [1, 2], "B": [0, 2], "C": [0, 0]}) | >>> df | A B C | 0 1 0 0 | 1 2 2 0 | | >>> df.any() | A True | B True | C False | dtype: bool | | Aggregating over the columns. | | >>> df = pd.DataFrame({"A": [True, False], "B": [1, 2]}) | >>> df | A B | 0 True 1 | 1 False 2 | | >>> df.any(axis='columns') | 0 True | 1 True | dtype: bool | | >>> df = pd.DataFrame({"A": [True, False], "B": [1, 0]}) | >>> df | A B | 0 True 1 | 1 False 0 | | >>> df.any(axis='columns') | 0 True | 1 False | dtype: bool | | Aggregating over the entire DataFrame with ``axis=None``. | | >>> df.any(axis=None) | True | | `any` for an empty DataFrame is an empty Series. | | >>> pd.DataFrame([]).any() | Series([], dtype: bool) | | append(self, to_append, ignore_index=False, verify_integrity=False) | Concatenate two or more Series. | | Parameters | ---------- | to_append : Series or list/tuple of Series | Series to append with self. | ignore_index : bool, default False | If True, do not use the index labels. | verify_integrity : bool, default False | If True, raise Exception on creating index with duplicates. | | Returns | ------- | Series | Concatenated Series. | | See Also | -------- | concat : General function to concatenate DataFrame or Series objects. | | Notes | ----- | Iteratively appending to a Series can be more computationally intensive | than a single concatenate. A better solution is to append values to a | list and then concatenate the list with the original Series all at | once. | | Examples | -------- | >>> s1 = pd.Series([1, 2, 3]) | >>> s2 = pd.Series([4, 5, 6]) | >>> s3 = pd.Series([4, 5, 6], index=[3, 4, 5]) | >>> s1.append(s2) | 0 1 | 1 2 | 2 3 | 0 4 | 1 5 | 2 6 | dtype: int64 | | >>> s1.append(s3) | 0 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | dtype: int64 | | With `ignore_index` set to True: | | >>> s1.append(s2, ignore_index=True) | 0 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | dtype: int64 | | With `verify_integrity` set to True: | | >>> s1.append(s2, verify_integrity=True) | Traceback (most recent call last): | ... | ValueError: Indexes have overlapping values: [0, 1, 2] | | apply(self, func, convert_dtype=True, args=(), **kwds) | Invoke function on values of Series. | | Can be ufunc (a NumPy function that applies to the entire Series) | or a Python function that only works on single values. | | Parameters | ---------- | func : function | Python function or NumPy ufunc to apply. | convert_dtype : bool, default True | Try to find better dtype for elementwise function results. If | False, leave as dtype=object. | args : tuple | Positional arguments passed to func after the series value. | **kwds | Additional keyword arguments passed to func. | | Returns | ------- | Series or DataFrame | If func returns a Series object the result will be a DataFrame. | | See Also | -------- | Series.map: For element-wise operations. | Series.agg: Only perform aggregating type operations. | Series.transform: Only perform transforming type operations. | | Examples | -------- | Create a series with typical summer temperatures for each city. | | >>> s = pd.Series([20, 21, 12], | ... index=['London', 'New York', 'Helsinki']) | >>> s | London 20 | New York 21 | Helsinki 12 | dtype: int64 | | Square the values by defining a function and passing it as an | argument to ``apply()``. | | >>> def square(x): | ... return x ** 2 | >>> s.apply(square) | London 400 | New York 441 | Helsinki 144 | dtype: int64 | | Square the values by passing an anonymous function as an | argument to ``apply()``. | | >>> s.apply(lambda x: x ** 2) | London 400 | New York 441 | Helsinki 144 | dtype: int64 | | Define a custom function that needs additional positional | arguments and pass these additional arguments using the | ``args`` keyword. | | >>> def subtract_custom_value(x, custom_value): | ... return x - custom_value | | >>> s.apply(subtract_custom_value, args=(5,)) | London 15 | New York 16 | Helsinki 7 | dtype: int64 | | Define a custom function that takes keyword arguments | and pass these arguments to ``apply``. | | >>> def add_custom_values(x, **kwargs): | ... for month in kwargs: | ... x += kwargs[month] | ... return x | | >>> s.apply(add_custom_values, june=30, july=20, august=25) | London 95 | New York 96 | Helsinki 87 | dtype: int64 | | Use a function from the Numpy library. | | >>> s.apply(np.log) | London 2.995732 | New York 3.044522 | Helsinki 2.484907 | dtype: float64 | | argsort(self, axis=0, kind='quicksort', order=None) | Override ndarray.argsort. Argsorts the value, omitting NA/null values, | and places the result in the same locations as the non-NA values. | | Parameters | ---------- | axis : {0 or "index"} | Has no effect but is accepted for compatibility with numpy. | kind : {'mergesort', 'quicksort', 'heapsort'}, default 'quicksort' | Choice of sorting algorithm. See np.sort for more | information. 'mergesort' is the only stable algorithm. | order : None | Has no effect but is accepted for compatibility with numpy. | | Returns | ------- | Series | Positions of values within the sort order with -1 indicating | nan values. | | See Also | -------- | numpy.ndarray.argsort | | autocorr(self, lag=1) | Compute the lag-N autocorrelation. | | This method computes the Pearson correlation between | the Series and its shifted self. | | Parameters | ---------- | lag : int, default 1 | Number of lags to apply before performing autocorrelation. | | Returns | ------- | float | The Pearson correlation between self and self.shift(lag). | | See Also | -------- | Series.corr : Compute the correlation between two Series. | Series.shift : Shift index by desired number of periods. | DataFrame.corr : Compute pairwise correlation of columns. | DataFrame.corrwith : Compute pairwise correlation between rows or | columns of two DataFrame objects. | | Notes | ----- | If the Pearson correlation is not well defined return 'NaN'. | | Examples | -------- | >>> s = pd.Series([0.25, 0.5, 0.2, -0.05]) | >>> s.autocorr() # doctest: +ELLIPSIS | 0.10355... | >>> s.autocorr(lag=2) # doctest: +ELLIPSIS | -0.99999... | | If the Pearson correlation is not well defined, then 'NaN' is returned. | | >>> s = pd.Series([1, 0, 0, 0]) | >>> s.autocorr() | nan | | between(self, left, right, inclusive=True) | Return boolean Series equivalent to left <= series <= right. | | This function returns a boolean vector containing `True` wherever the | corresponding Series element is between the boundary values `left` and | `right`. NA values are treated as `False`. | | Parameters | ---------- | left : scalar or list-like | Left boundary. | right : scalar or list-like | Right boundary. | inclusive : bool, default True | Include boundaries. | | Returns | ------- | Series | Series representing whether each element is between left and | right (inclusive). | | See Also | -------- | Series.gt : Greater than of series and other. | Series.lt : Less than of series and other. | | Notes | ----- | This function is equivalent to ``(left <= ser) & (ser <= right)`` | | Examples | -------- | >>> s = pd.Series([2, 0, 4, 8, np.nan]) | | Boundary values are included by default: | | >>> s.between(1, 4) | 0 True | 1 False | 2 True | 3 False | 4 False | dtype: bool | | With `inclusive` set to ``False`` boundary values are excluded: | | >>> s.between(1, 4, inclusive=False) | 0 True | 1 False | 2 False | 3 False | 4 False | dtype: bool | | `left` and `right` can be any scalar value: | | >>> s = pd.Series(['Alice', 'Bob', 'Carol', 'Eve']) | >>> s.between('Anna', 'Daniel') | 0 False | 1 True | 2 True | 3 False | dtype: bool | | combine(self, other, func, fill_value=None) | Combine the Series with a Series or scalar according to `func`. | | Combine the Series and `other` using `func` to perform elementwise | selection for combined Series. | `fill_value` is assumed when value is missing at some index | from one of the two objects being combined. | | Parameters | ---------- | other : Series or scalar | The value(s) to be combined with the `Series`. | func : function | Function that takes two scalars as inputs and returns an element. | fill_value : scalar, optional | The value to assume when an index is missing from | one Series or the other. The default specifies to use the | appropriate NaN value for the underlying dtype of the Series. | | Returns | ------- | Series | The result of combining the Series with the other object. | | See Also | -------- | Series.combine_first : Combine Series values, choosing the calling | Series' values first. | | Examples | -------- | Consider 2 Datasets ``s1`` and ``s2`` containing | highest clocked speeds of different birds. | | >>> s1 = pd.Series({'falcon': 330.0, 'eagle': 160.0}) | >>> s1 | falcon 330.0 | eagle 160.0 | dtype: float64 | >>> s2 = pd.Series({'falcon': 345.0, 'eagle': 200.0, 'duck': 30.0}) | >>> s2 | falcon 345.0 | eagle 200.0 | duck 30.0 | dtype: float64 | | Now, to combine the two datasets and view the highest speeds | of the birds across the two datasets | | >>> s1.combine(s2, max) | duck NaN | eagle 200.0 | falcon 345.0 | dtype: float64 | | In the previous example, the resulting value for duck is missing, | because the maximum of a NaN and a float is a NaN. | So, in the example, we set ``fill_value=0``, | so the maximum value returned will be the value from some dataset. | | >>> s1.combine(s2, max, fill_value=0) | duck 30.0 | eagle 200.0 | falcon 345.0 | dtype: float64 | | combine_first(self, other) | Combine Series values, choosing the calling Series's values first. | | Parameters | ---------- | other : Series | The value(s) to be combined with the `Series`. | | Returns | ------- | Series | The result of combining the Series with the other object. | | See Also | -------- | Series.combine : Perform elementwise operation on two Series | using a given function. | | Notes | ----- | Result index will be the union of the two indexes. | | Examples | -------- | >>> s1 = pd.Series([1, np.nan]) | >>> s2 = pd.Series([3, 4]) | >>> s1.combine_first(s2) | 0 1.0 | 1 4.0 | dtype: float64 | | corr(self, other, method='pearson', min_periods=None) | Compute correlation with `other` Series, excluding missing values. | | Parameters | ---------- | other : Series | Series with which to compute the correlation. | method : {'pearson', 'kendall', 'spearman'} or callable | Method used to compute correlation: | | - pearson : Standard correlation coefficient | - kendall : Kendall Tau correlation coefficient | - spearman : Spearman rank correlation | - callable: Callable with input two 1d ndarrays and returning a float. | | .. versionadded:: 0.24.0 | Note that the returned matrix from corr will have 1 along the | diagonals and will be symmetric regardless of the callable's | behavior. | min_periods : int, optional | Minimum number of observations needed to have a valid result. | | Returns | ------- | float | Correlation with other. | | Examples | -------- | >>> def histogram_intersection(a, b): | ... v = np.minimum(a, b).sum().round(decimals=1) | ... return v | >>> s1 = pd.Series([.2, .0, .6, .2]) | >>> s2 = pd.Series([.3, .6, .0, .1]) | >>> s1.corr(s2, method=histogram_intersection) | 0.3 | | count(self, level=None) | Return number of non-NA/null observations in the Series. | | Parameters | ---------- | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a smaller Series. | | Returns | ------- | int or Series (if level specified) | Number of non-null values in the Series. | | Examples | -------- | >>> s = pd.Series([0.0, 1.0, np.nan]) | >>> s.count() | 2 | | cov(self, other, min_periods=None) | Compute covariance with Series, excluding missing values. | | Parameters | ---------- | other : Series | Series with which to compute the covariance. | min_periods : int, optional | Minimum number of observations needed to have a valid result. | | Returns | ------- | float | Covariance between Series and other normalized by N-1 | (unbiased estimator). | | Examples | -------- | >>> s1 = pd.Series([0.90010907, 0.13484424, 0.62036035]) | >>> s2 = pd.Series([0.12528585, 0.26962463, 0.51111198]) | >>> s1.cov(s2) | -0.01685762652715874 | | cummax(self, axis=None, skipna=True, *args, **kwargs) | Return cumulative maximum over a DataFrame or Series axis. | | Returns a DataFrame or Series of the same size containing the cumulative | maximum. | | Parameters | ---------- | axis : {0 or 'index', 1 or 'columns'}, default 0 | The index or the name of the axis. 0 is equivalent to None or 'index'. | skipna : bool, default True | Exclude NA/null values. If an entire row/column is NA, the result | will be NA. | *args, **kwargs : | Additional keywords have no effect but might be accepted for | compatibility with NumPy. | | Returns | ------- | scalar or Series | | See Also | -------- | core.window.Expanding.max : Similar functionality | but ignores ``NaN`` values. | Series.max : Return the maximum over | Series axis. | Series.cummax : Return cumulative maximum over Series axis. | Series.cummin : Return cumulative minimum over Series axis. | Series.cumsum : Return cumulative sum over Series axis. | Series.cumprod : Return cumulative product over Series axis. | | Examples | -------- | **Series** | | >>> s = pd.Series([2, np.nan, 5, -1, 0]) | >>> s | 0 2.0 | 1 NaN | 2 5.0 | 3 -1.0 | 4 0.0 | dtype: float64 | | By default, NA values are ignored. | | >>> s.cummax() | 0 2.0 | 1 NaN | 2 5.0 | 3 5.0 | 4 5.0 | dtype: float64 | | To include NA values in the operation, use ``skipna=False`` | | >>> s.cummax(skipna=False) | 0 2.0 | 1 NaN | 2 NaN | 3 NaN | 4 NaN | dtype: float64 | | **DataFrame** | | >>> df = pd.DataFrame([[2.0, 1.0], | ... [3.0, np.nan], | ... [1.0, 0.0]], | ... columns=list('AB')) | >>> df | A B | 0 2.0 1.0 | 1 3.0 NaN | 2 1.0 0.0 | | By default, iterates over rows and finds the maximum | in each column. This is equivalent to ``axis=None`` or ``axis='index'``. | | >>> df.cummax() | A B | 0 2.0 1.0 | 1 3.0 NaN | 2 3.0 1.0 | | To iterate over columns and find the maximum in each row, | use ``axis=1`` | | >>> df.cummax(axis=1) | A B | 0 2.0 2.0 | 1 3.0 NaN | 2 1.0 1.0 | | cummin(self, axis=None, skipna=True, *args, **kwargs) | Return cumulative minimum over a DataFrame or Series axis. | | Returns a DataFrame or Series of the same size containing the cumulative | minimum. | | Parameters | ---------- | axis : {0 or 'index', 1 or 'columns'}, default 0 | The index or the name of the axis. 0 is equivalent to None or 'index'. | skipna : bool, default True | Exclude NA/null values. If an entire row/column is NA, the result | will be NA. | *args, **kwargs : | Additional keywords have no effect but might be accepted for | compatibility with NumPy. | | Returns | ------- | scalar or Series | | See Also | -------- | core.window.Expanding.min : Similar functionality | but ignores ``NaN`` values. | Series.min : Return the minimum over | Series axis. | Series.cummax : Return cumulative maximum over Series axis. | Series.cummin : Return cumulative minimum over Series axis. | Series.cumsum : Return cumulative sum over Series axis. | Series.cumprod : Return cumulative product over Series axis. | | Examples | -------- | **Series** | | >>> s = pd.Series([2, np.nan, 5, -1, 0]) | >>> s | 0 2.0 | 1 NaN | 2 5.0 | 3 -1.0 | 4 0.0 | dtype: float64 | | By default, NA values are ignored. | | >>> s.cummin() | 0 2.0 | 1 NaN | 2 2.0 | 3 -1.0 | 4 -1.0 | dtype: float64 | | To include NA values in the operation, use ``skipna=False`` | | >>> s.cummin(skipna=False) | 0 2.0 | 1 NaN | 2 NaN | 3 NaN | 4 NaN | dtype: float64 | | **DataFrame** | | >>> df = pd.DataFrame([[2.0, 1.0], | ... [3.0, np.nan], | ... [1.0, 0.0]], | ... columns=list('AB')) | >>> df | A B | 0 2.0 1.0 | 1 3.0 NaN | 2 1.0 0.0 | | By default, iterates over rows and finds the minimum | in each column. This is equivalent to ``axis=None`` or ``axis='index'``. | | >>> df.cummin() | A B | 0 2.0 1.0 | 1 2.0 NaN | 2 1.0 0.0 | | To iterate over columns and find the minimum in each row, | use ``axis=1`` | | >>> df.cummin(axis=1) | A B | 0 2.0 1.0 | 1 3.0 NaN | 2 1.0 0.0 | | cumprod(self, axis=None, skipna=True, *args, **kwargs) | Return cumulative product over a DataFrame or Series axis. | | Returns a DataFrame or Series of the same size containing the cumulative | product. | | Parameters | ---------- | axis : {0 or 'index', 1 or 'columns'}, default 0 | The index or the name of the axis. 0 is equivalent to None or 'index'. | skipna : bool, default True | Exclude NA/null values. If an entire row/column is NA, the result | will be NA. | *args, **kwargs : | Additional keywords have no effect but might be accepted for | compatibility with NumPy. | | Returns | ------- | scalar or Series | | See Also | -------- | core.window.Expanding.prod : Similar functionality | but ignores ``NaN`` values. | Series.prod : Return the product over | Series axis. | Series.cummax : Return cumulative maximum over Series axis. | Series.cummin : Return cumulative minimum over Series axis. | Series.cumsum : Return cumulative sum over Series axis. | Series.cumprod : Return cumulative product over Series axis. | | Examples | -------- | **Series** | | >>> s = pd.Series([2, np.nan, 5, -1, 0]) | >>> s | 0 2.0 | 1 NaN | 2 5.0 | 3 -1.0 | 4 0.0 | dtype: float64 | | By default, NA values are ignored. | | >>> s.cumprod() | 0 2.0 | 1 NaN | 2 10.0 | 3 -10.0 | 4 -0.0 | dtype: float64 | | To include NA values in the operation, use ``skipna=False`` | | >>> s.cumprod(skipna=False) | 0 2.0 | 1 NaN | 2 NaN | 3 NaN | 4 NaN | dtype: float64 | | **DataFrame** | | >>> df = pd.DataFrame([[2.0, 1.0], | ... [3.0, np.nan], | ... [1.0, 0.0]], | ... columns=list('AB')) | >>> df | A B | 0 2.0 1.0 | 1 3.0 NaN | 2 1.0 0.0 | | By default, iterates over rows and finds the product | in each column. This is equivalent to ``axis=None`` or ``axis='index'``. | | >>> df.cumprod() | A B | 0 2.0 1.0 | 1 6.0 NaN | 2 6.0 0.0 | | To iterate over columns and find the product in each row, | use ``axis=1`` | | >>> df.cumprod(axis=1) | A B | 0 2.0 2.0 | 1 3.0 NaN | 2 1.0 0.0 | | cumsum(self, axis=None, skipna=True, *args, **kwargs) | Return cumulative sum over a DataFrame or Series axis. | | Returns a DataFrame or Series of the same size containing the cumulative | sum. | | Parameters | ---------- | axis : {0 or 'index', 1 or 'columns'}, default 0 | The index or the name of the axis. 0 is equivalent to None or 'index'. | skipna : bool, default True | Exclude NA/null values. If an entire row/column is NA, the result | will be NA. | *args, **kwargs : | Additional keywords have no effect but might be accepted for | compatibility with NumPy. | | Returns | ------- | scalar or Series | | See Also | -------- | core.window.Expanding.sum : Similar functionality | but ignores ``NaN`` values. | Series.sum : Return the sum over | Series axis. | Series.cummax : Return cumulative maximum over Series axis. | Series.cummin : Return cumulative minimum over Series axis. | Series.cumsum : Return cumulative sum over Series axis. | Series.cumprod : Return cumulative product over Series axis. | | Examples | -------- | **Series** | | >>> s = pd.Series([2, np.nan, 5, -1, 0]) | >>> s | 0 2.0 | 1 NaN | 2 5.0 | 3 -1.0 | 4 0.0 | dtype: float64 | | By default, NA values are ignored. | | >>> s.cumsum() | 0 2.0 | 1 NaN | 2 7.0 | 3 6.0 | 4 6.0 | dtype: float64 | | To include NA values in the operation, use ``skipna=False`` | | >>> s.cumsum(skipna=False) | 0 2.0 | 1 NaN | 2 NaN | 3 NaN | 4 NaN | dtype: float64 | | **DataFrame** | | >>> df = pd.DataFrame([[2.0, 1.0], | ... [3.0, np.nan], | ... [1.0, 0.0]], | ... columns=list('AB')) | >>> df | A B | 0 2.0 1.0 | 1 3.0 NaN | 2 1.0 0.0 | | By default, iterates over rows and finds the sum | in each column. This is equivalent to ``axis=None`` or ``axis='index'``. | | >>> df.cumsum() | A B | 0 2.0 1.0 | 1 5.0 NaN | 2 6.0 1.0 | | To iterate over columns and find the sum in each row, | use ``axis=1`` | | >>> df.cumsum(axis=1) | A B | 0 2.0 3.0 | 1 3.0 NaN | 2 1.0 1.0 | | diff(self, periods=1) | First discrete difference of element. | | Calculates the difference of a Series element compared with another | element in the Series (default is element in previous row). | | Parameters | ---------- | periods : int, default 1 | Periods to shift for calculating difference, accepts negative | values. | | Returns | ------- | Series | First differences of the Series. | | See Also | -------- | Series.pct_change: Percent change over given number of periods. | Series.shift: Shift index by desired number of periods with an | optional time freq. | DataFrame.diff: First discrete difference of object. | | Notes | ----- | For boolean dtypes, this uses :meth:`operator.xor` rather than | :meth:`operator.sub`. | | Examples | -------- | Difference with previous row | | >>> s = pd.Series([1, 1, 2, 3, 5, 8]) | >>> s.diff() | 0 NaN | 1 0.0 | 2 1.0 | 3 1.0 | 4 2.0 | 5 3.0 | dtype: float64 | | Difference with 3rd previous row | | >>> s.diff(periods=3) | 0 NaN | 1 NaN | 2 NaN | 3 2.0 | 4 4.0 | 5 6.0 | dtype: float64 | | Difference with following row | | >>> s.diff(periods=-1) | 0 0.0 | 1 -1.0 | 2 -1.0 | 3 -2.0 | 4 -3.0 | 5 NaN | dtype: float64 | | div = truediv(self, other, level=None, fill_value=None, axis=0) | | divide = truediv(self, other, level=None, fill_value=None, axis=0) | | divmod(self, other, level=None, fill_value=None, axis=0) | Return Integer division and modulo of series and other, element-wise (binary operator `divmod`). | | Equivalent to ``series divmod other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.rdivmod | | dot(self, other) | Compute the dot product between the Series and the columns of other. | | This method computes the dot product between the Series and another | one, or the Series and each columns of a DataFrame, or the Series and | each columns of an array. | | It can also be called using `self @ other` in Python >= 3.5. | | Parameters | ---------- | other : Series, DataFrame or array-like | The other object to compute the dot product with its columns. | | Returns | ------- | scalar, Series or numpy.ndarray | Return the dot product of the Series and other if other is a | Series, the Series of the dot product of Series and each rows of | other if other is a DataFrame or a numpy.ndarray between the Series | and each columns of the numpy array. | | See Also | -------- | DataFrame.dot: Compute the matrix product with the DataFrame. | Series.mul: Multiplication of series and other, element-wise. | | Notes | ----- | The Series and other has to share the same index if other is a Series | or a DataFrame. | | Examples | -------- | >>> s = pd.Series([0, 1, 2, 3]) | >>> other = pd.Series([-1, 2, -3, 4]) | >>> s.dot(other) | 8 | >>> s @ other | 8 | >>> df = pd.DataFrame([[0, 1], [-2, 3], [4, -5], [6, 7]]) | >>> s.dot(df) | 0 24 | 1 14 | dtype: int64 | >>> arr = np.array([[0, 1], [-2, 3], [4, -5], [6, 7]]) | >>> s.dot(arr) | array([24, 14]) | | drop(self, labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise') | Return Series with specified index labels removed. | | Remove elements of a Series based on specifying the index labels. | When using a multi-index, labels on different levels can be removed | by specifying the level. | | Parameters | ---------- | labels : single label or list-like | Index labels to drop. | axis : 0, default 0 | Redundant for application on Series. | index : single label or list-like | Redundant for application on Series, but 'index' can be used instead | of 'labels'. | | .. versionadded:: 0.21.0 | columns : single label or list-like | No change is made to the Series; use 'index' or 'labels' instead. | | .. versionadded:: 0.21.0 | level : int or level name, optional | For MultiIndex, level for which the labels will be removed. | inplace : bool, default False | If True, do operation inplace and return None. | errors : {'ignore', 'raise'}, default 'raise' | If 'ignore', suppress error and only existing labels are dropped. | | Returns | ------- | Series | Series with specified index labels removed. | | Raises | ------ | KeyError | If none of the labels are found in the index. | | See Also | -------- | Series.reindex : Return only specified index labels of Series. | Series.dropna : Return series without null values. | Series.drop_duplicates : Return Series with duplicate values removed. | DataFrame.drop : Drop specified labels from rows or columns. | | Examples | -------- | >>> s = pd.Series(data=np.arange(3), index=['A', 'B', 'C']) | >>> s | A 0 | B 1 | C 2 | dtype: int64 | | Drop labels B en C | | >>> s.drop(labels=['B', 'C']) | A 0 | dtype: int64 | | Drop 2nd level label in MultiIndex Series | | >>> midx = pd.MultiIndex(levels=[['lama', 'cow', 'falcon'], | ... ['speed', 'weight', 'length']], | ... codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2], | ... [0, 1, 2, 0, 1, 2, 0, 1, 2]]) | >>> s = pd.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3], | ... index=midx) | >>> s | lama speed 45.0 | weight 200.0 | length 1.2 | cow speed 30.0 | weight 250.0 | length 1.5 | falcon speed 320.0 | weight 1.0 | length 0.3 | dtype: float64 | | >>> s.drop(labels='weight', level=1) | lama speed 45.0 | length 1.2 | cow speed 30.0 | length 1.5 | falcon speed 320.0 | length 0.3 | dtype: float64 | | drop_duplicates(self, keep='first', inplace=False) | Return Series with duplicate values removed. | | Parameters | ---------- | keep : {'first', 'last', ``False``}, default 'first' | Method to handle dropping duplicates: | | - 'first' : Drop duplicates except for the first occurrence. | - 'last' : Drop duplicates except for the last occurrence. | - ``False`` : Drop all duplicates. | | inplace : bool, default ``False`` | If ``True``, performs operation inplace and returns None. | | Returns | ------- | Series | Series with duplicates dropped. | | See Also | -------- | Index.drop_duplicates : Equivalent method on Index. | DataFrame.drop_duplicates : Equivalent method on DataFrame. | Series.duplicated : Related method on Series, indicating duplicate | Series values. | | Examples | -------- | Generate a Series with duplicated entries. | | >>> s = pd.Series(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'], | ... name='animal') | >>> s | 0 lama | 1 cow | 2 lama | 3 beetle | 4 lama | 5 hippo | Name: animal, dtype: object | | With the 'keep' parameter, the selection behaviour of duplicated values | can be changed. The value 'first' keeps the first occurrence for each | set of duplicated entries. The default value of keep is 'first'. | | >>> s.drop_duplicates() | 0 lama | 1 cow | 3 beetle | 5 hippo | Name: animal, dtype: object | | The value 'last' for parameter 'keep' keeps the last occurrence for | each set of duplicated entries. | | >>> s.drop_duplicates(keep='last') | 1 cow | 3 beetle | 4 lama | 5 hippo | Name: animal, dtype: object | | The value ``False`` for parameter 'keep' discards all sets of | duplicated entries. Setting the value of 'inplace' to ``True`` performs | the operation inplace and returns ``None``. | | >>> s.drop_duplicates(keep=False, inplace=True) | >>> s | 1 cow | 3 beetle | 5 hippo | Name: animal, dtype: object | | dropna(self, axis=0, inplace=False, how=None) | Return a new Series with missing values removed. | | See the :ref:`User Guide <missing_data>` for more on which values are | considered missing, and how to work with missing data. | | Parameters | ---------- | axis : {0 or 'index'}, default 0 | There is only one axis to drop values from. | inplace : bool, default False | If True, do operation inplace and return None. | how : str, optional | Not in use. Kept for compatibility. | | Returns | ------- | Series | Series with NA entries dropped from it. | | See Also | -------- | Series.isna: Indicate missing values. | Series.notna : Indicate existing (non-missing) values. | Series.fillna : Replace missing values. | DataFrame.dropna : Drop rows or columns which contain NA values. | Index.dropna : Drop missing indices. | | Examples | -------- | >>> ser = pd.Series([1., 2., np.nan]) | >>> ser | 0 1.0 | 1 2.0 | 2 NaN | dtype: float64 | | Drop NA values from a Series. | | >>> ser.dropna() | 0 1.0 | 1 2.0 | dtype: float64 | | Keep the Series with valid entries in the same variable. | | >>> ser.dropna(inplace=True) | >>> ser | 0 1.0 | 1 2.0 | dtype: float64 | | Empty strings are not considered NA values. ``None`` is considered an | NA value. | | >>> ser = pd.Series([np.NaN, 2, pd.NaT, '', None, 'I stay']) | >>> ser | 0 NaN | 1 2 | 2 NaT | 3 | 4 None | 5 I stay | dtype: object | >>> ser.dropna() | 1 2 | 3 | 5 I stay | dtype: object | | duplicated(self, keep='first') | Indicate duplicate Series values. | | Duplicated values are indicated as ``True`` values in the resulting | Series. Either all duplicates, all except the first or all except the | last occurrence of duplicates can be indicated. | | Parameters | ---------- | keep : {'first', 'last', False}, default 'first' | Method to handle dropping duplicates: | | - 'first' : Mark duplicates as ``True`` except for the first | occurrence. | - 'last' : Mark duplicates as ``True`` except for the last | occurrence. | - ``False`` : Mark all duplicates as ``True``. | | Returns | ------- | Series | Series indicating whether each value has occurred in the | preceding values. | | See Also | -------- | Index.duplicated : Equivalent method on pandas.Index. | DataFrame.duplicated : Equivalent method on pandas.DataFrame. | Series.drop_duplicates : Remove duplicate values from Series. | | Examples | -------- | By default, for each set of duplicated values, the first occurrence is | set on False and all others on True: | | >>> animals = pd.Series(['lama', 'cow', 'lama', 'beetle', 'lama']) | >>> animals.duplicated() | 0 False | 1 False | 2 True | 3 False | 4 True | dtype: bool | | which is equivalent to | | >>> animals.duplicated(keep='first') | 0 False | 1 False | 2 True | 3 False | 4 True | dtype: bool | | By using 'last', the last occurrence of each set of duplicated values | is set on False and all others on True: | | >>> animals.duplicated(keep='last') | 0 True | 1 False | 2 True | 3 False | 4 False | dtype: bool | | By setting keep on ``False``, all duplicates are True: | | >>> animals.duplicated(keep=False) | 0 True | 1 False | 2 True | 3 False | 4 True | dtype: bool | | eq(self, other, level=None, fill_value=None, axis=0) | Return Equal to of series and other, element-wise (binary operator `eq`). | | Equivalent to ``series == other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.None | | ewm(self, com=None, span=None, halflife=None, alpha=None, min_periods=0, adjust=True, ignore_na=False, axis=0) | Provide exponential weighted functions. | | Parameters | ---------- | com : float, optional | Specify decay in terms of center of mass, | :math:`\alpha = 1 / (1 + com),\text{ for } com \geq 0`. | span : float, optional | Specify decay in terms of span, | :math:`\alpha = 2 / (span + 1),\text{ for } span \geq 1`. | halflife : float, optional | Specify decay in terms of half-life, | :math:`\alpha = 1 - exp(log(0.5) / halflife),\text{for} halflife > 0`. | alpha : float, optional | Specify smoothing factor :math:`\alpha` directly, | :math:`0 < \alpha \leq 1`. | min_periods : int, default 0 | Minimum number of observations in window required to have a value | (otherwise result is NA). | adjust : bool, default True | Divide by decaying adjustment factor in beginning periods to account | for imbalance in relative weightings | (viewing EWMA as a moving average). | ignore_na : bool, default False | Ignore missing values when calculating weights; | specify True to reproduce pre-0.15.0 behavior. | axis : {0 or 'index', 1 or 'columns'}, default 0 | The axis to use. The value 0 identifies the rows, and 1 | identifies the columns. | | Returns | ------- | DataFrame | A Window sub-classed for the particular operation. | | See Also | -------- | rolling : Provides rolling window calculations. | expanding : Provides expanding transformations. | | Notes | ----- | Exactly one of center of mass, span, half-life, and alpha must be provided. | Allowed values and relationship between the parameters are specified in the | parameter descriptions above; see the link at the end of this section for | a detailed explanation. | | When adjust is True (default), weighted averages are calculated using | weights (1-alpha)**(n-1), (1-alpha)**(n-2), ..., 1-alpha, 1. | | When adjust is False, weighted averages are calculated recursively as: | weighted_average[0] = arg[0]; | weighted_average[i] = (1-alpha)*weighted_average[i-1] + alpha*arg[i]. | | When ignore_na is False (default), weights are based on absolute positions. | For example, the weights of x and y used in calculating the final weighted | average of [x, None, y] are (1-alpha)**2 and 1 (if adjust is True), and | (1-alpha)**2 and alpha (if adjust is False). | | When ignore_na is True (reproducing pre-0.15.0 behavior), weights are based | on relative positions. For example, the weights of x and y used in | calculating the final weighted average of [x, None, y] are 1-alpha and 1 | (if adjust is True), and 1-alpha and alpha (if adjust is False). | | More details can be found at | https://pandas.pydata.org/pandas-docs/stable/user_guide/computation.html#exponentially-weighted-windows | | Examples | -------- | | >>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]}) | >>> df | B | 0 0.0 | 1 1.0 | 2 2.0 | 3 NaN | 4 4.0 | | >>> df.ewm(com=0.5).mean() | B | 0 0.000000 | 1 0.750000 | 2 1.615385 | 3 1.615385 | 4 3.670213 | | expanding(self, min_periods=1, center=False, axis=0) | Provide expanding transformations. | | Parameters | ---------- | min_periods : int, default 1 | Minimum number of observations in window required to have a value | (otherwise result is NA). | center : bool, default False | Set the labels at the center of the window. | axis : int or str, default 0 | | Returns | ------- | a Window sub-classed for the particular operation | | See Also | -------- | rolling : Provides rolling window calculations. | ewm : Provides exponential weighted functions. | | Notes | ----- | By default, the result is set to the right edge of the window. This can be | changed to the center of the window by setting ``center=True``. | | Examples | -------- | | >>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]}) | B | 0 0.0 | 1 1.0 | 2 2.0 | 3 NaN | 4 4.0 | | >>> df.expanding(2).sum() | B | 0 NaN | 1 1.0 | 2 3.0 | 3 3.0 | 4 7.0 | | explode(self) -> 'Series' | Transform each element of a list-like to a row, replicating the | index values. | | .. versionadded:: 0.25.0 | | Returns | ------- | Series | Exploded lists to rows; index will be duplicated for these rows. | | See Also | -------- | Series.str.split : Split string values on specified separator. | Series.unstack : Unstack, a.k.a. pivot, Series with MultiIndex | to produce DataFrame. | DataFrame.melt : Unpivot a DataFrame from wide format to long format. | DataFrame.explode : Explode a DataFrame from list-like | columns to long format. | | Notes | ----- | This routine will explode list-likes including lists, tuples, | Series, and np.ndarray. The result dtype of the subset rows will | be object. Scalars will be returned unchanged. Empty list-likes will | result in a np.nan for that row. | | Examples | -------- | >>> s = pd.Series([[1, 2, 3], 'foo', [], [3, 4]]) | >>> s | 0 [1, 2, 3] | 1 foo | 2 [] | 3 [3, 4] | dtype: object | | >>> s.explode() | 0 1 | 0 2 | 0 3 | 1 foo | 2 NaN | 3 3 | 3 4 | dtype: object | | fillna(self, value=None, method=None, axis=None, inplace=False, limit=None, downcast=None) -> Union[ForwardRef('Series'), NoneType] | Fill NA/NaN values using the specified method. | | Parameters | ---------- | value : scalar, dict, Series, or DataFrame | Value to use to fill holes (e.g. 0), alternately a | dict/Series/DataFrame of values specifying which value to use for | each index (for a Series) or column (for a DataFrame). Values not | in the dict/Series/DataFrame will not be filled. This value cannot | be a list. | method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None | Method to use for filling holes in reindexed Series | pad / ffill: propagate last valid observation forward to next valid | backfill / bfill: use next valid observation to fill gap. | axis : {0 or 'index'} | Axis along which to fill missing values. | inplace : bool, default False | If True, fill in-place. Note: this will modify any | other views on this object (e.g., a no-copy slice for a column in a | DataFrame). | limit : int, default None | If method is specified, this is the maximum number of consecutive | NaN values to forward/backward fill. In other words, if there is | a gap with more than this number of consecutive NaNs, it will only | be partially filled. If method is not specified, this is the | maximum number of entries along the entire axis where NaNs will be | filled. Must be greater than 0 if not None. | downcast : dict, default is None | A dict of item->dtype of what to downcast if possible, | or the string 'infer' which will try to downcast to an appropriate | equal type (e.g. float64 to int64 if possible). | | Returns | ------- | Series or None | Object with missing values filled or None if ``inplace=True``. | | See Also | -------- | interpolate : Fill NaN values using interpolation. | reindex : Conform object to new index. | asfreq : Convert TimeSeries to specified frequency. | | Examples | -------- | >>> df = pd.DataFrame([[np.nan, 2, np.nan, 0], | ... [3, 4, np.nan, 1], | ... [np.nan, np.nan, np.nan, 5], | ... [np.nan, 3, np.nan, 4]], | ... columns=list('ABCD')) | >>> df | A B C D | 0 NaN 2.0 NaN 0 | 1 3.0 4.0 NaN 1 | 2 NaN NaN NaN 5 | 3 NaN 3.0 NaN 4 | | Replace all NaN elements with 0s. | | >>> df.fillna(0) | A B C D | 0 0.0 2.0 0.0 0 | 1 3.0 4.0 0.0 1 | 2 0.0 0.0 0.0 5 | 3 0.0 3.0 0.0 4 | | We can also propagate non-null values forward or backward. | | >>> df.fillna(method='ffill') | A B C D | 0 NaN 2.0 NaN 0 | 1 3.0 4.0 NaN 1 | 2 3.0 4.0 NaN 5 | 3 3.0 3.0 NaN 4 | | Replace all NaN elements in column 'A', 'B', 'C', and 'D', with 0, 1, | 2, and 3 respectively. | | >>> values = {'A': 0, 'B': 1, 'C': 2, 'D': 3} | >>> df.fillna(value=values) | A B C D | 0 0.0 2.0 2.0 0 | 1 3.0 4.0 2.0 1 | 2 0.0 1.0 2.0 5 | 3 0.0 3.0 2.0 4 | | Only replace the first NaN element. | | >>> df.fillna(value=values, limit=1) | A B C D | 0 0.0 2.0 2.0 0 | 1 3.0 4.0 NaN 1 | 2 NaN 1.0 NaN 5 | 3 NaN 3.0 NaN 4 | | floordiv(self, other, level=None, fill_value=None, axis=0) | Return Integer division of series and other, element-wise (binary operator `floordiv`). | | Equivalent to ``series // other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.rfloordiv | | Examples | -------- | >>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd']) | >>> a | a 1.0 | b 1.0 | c 1.0 | d NaN | dtype: float64 | >>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e']) | >>> b | a 1.0 | b NaN | d 1.0 | e NaN | dtype: float64 | >>> a.floordiv(b, fill_value=0) | a 1.0 | b NaN | c NaN | d 0.0 | e NaN | dtype: float64 | | ge(self, other, level=None, fill_value=None, axis=0) | Return Greater than or equal to of series and other, element-wise (binary operator `ge`). | | Equivalent to ``series >= other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.None | | groupby(self, by=None, axis=0, level=None, as_index: bool = True, sort: bool = True, group_keys: bool = True, squeeze: bool = False, observed: bool = False) -> 'groupby_generic.SeriesGroupBy' | Group Series using a mapper or by a Series of columns. | | A groupby operation involves some combination of splitting the | object, applying a function, and combining the results. This can be | used to group large amounts of data and compute operations on these | groups. | | Parameters | ---------- | by : mapping, function, label, or list of labels | Used to determine the groups for the groupby. | If ``by`` is a function, it's called on each value of the object's | index. If a dict or Series is passed, the Series or dict VALUES | will be used to determine the groups (the Series' values are first | aligned; see ``.align()`` method). If an ndarray is passed, the | values are used as-is determine the groups. A label or list of | labels may be passed to group by the columns in ``self``. Notice | that a tuple is interpreted as a (single) key. | axis : {0 or 'index', 1 or 'columns'}, default 0 | Split along rows (0) or columns (1). | level : int, level name, or sequence of such, default None | If the axis is a MultiIndex (hierarchical), group by a particular | level or levels. | as_index : bool, default True | For aggregated output, return object with group labels as the | index. Only relevant for DataFrame input. as_index=False is | effectively "SQL-style" grouped output. | sort : bool, default True | Sort group keys. Get better performance by turning this off. | Note this does not influence the order of observations within each | group. Groupby preserves the order of rows within each group. | group_keys : bool, default True | When calling apply, add group keys to index to identify pieces. | squeeze : bool, default False | Reduce the dimensionality of the return type if possible, | otherwise return a consistent type. | observed : bool, default False | This only applies if any of the groupers are Categoricals. | If True: only show observed values for categorical groupers. | If False: show all values for categorical groupers. | | .. versionadded:: 0.23.0 | | Returns | ------- | SeriesGroupBy | Returns a groupby object that contains information about the groups. | | See Also | -------- | resample : Convenience method for frequency conversion and resampling | of time series. | | Notes | ----- | See the `user guide | <https://pandas.pydata.org/pandas-docs/stable/groupby.html>`_ for more. | | Examples | -------- | >>> ser = pd.Series([390., 350., 30., 20.], | ... index=['Falcon', 'Falcon', 'Parrot', 'Parrot'], name="Max Speed") | >>> ser | Falcon 390.0 | Falcon 350.0 | Parrot 30.0 | Parrot 20.0 | Name: Max Speed, dtype: float64 | >>> ser.groupby(["a", "b", "a", "b"]).mean() | a 210.0 | b 185.0 | Name: Max Speed, dtype: float64 | >>> ser.groupby(level=0).mean() | Falcon 370.0 | Parrot 25.0 | Name: Max Speed, dtype: float64 | >>> ser.groupby(ser > 100).mean() | Max Speed | False 25.0 | True 370.0 | Name: Max Speed, dtype: float64 | | **Grouping by Indexes** | | We can groupby different levels of a hierarchical index | using the `level` parameter: | | >>> arrays = [['Falcon', 'Falcon', 'Parrot', 'Parrot'], | ... ['Captive', 'Wild', 'Captive', 'Wild']] | >>> index = pd.MultiIndex.from_arrays(arrays, names=('Animal', 'Type')) | >>> ser = pd.Series([390., 350., 30., 20.], index=index, name="Max Speed") | >>> ser | Animal Type | Falcon Captive 390.0 | Wild 350.0 | Parrot Captive 30.0 | Wild 20.0 | Name: Max Speed, dtype: float64 | >>> ser.groupby(level=0).mean() | Animal | Falcon 370.0 | Parrot 25.0 | Name: Max Speed, dtype: float64 | >>> ser.groupby(level="Type").mean() | Type | Captive 210.0 | Wild 185.0 | Name: Max Speed, dtype: float64 | | gt(self, other, level=None, fill_value=None, axis=0) | Return Greater than of series and other, element-wise (binary operator `gt`). | | Equivalent to ``series > other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.None | | hist = hist_series(self, by=None, ax=None, grid=True, xlabelsize=None, xrot=None, ylabelsize=None, yrot=None, figsize=None, bins=10, backend=None, **kwargs) | Draw histogram of the input series using matplotlib. | | Parameters | ---------- | by : object, optional | If passed, then used to form histograms for separate groups. | ax : matplotlib axis object | If not passed, uses gca(). | grid : bool, default True | Whether to show axis grid lines. | xlabelsize : int, default None | If specified changes the x-axis label size. | xrot : float, default None | Rotation of x axis labels. | ylabelsize : int, default None | If specified changes the y-axis label size. | yrot : float, default None | Rotation of y axis labels. | figsize : tuple, default None | Figure size in inches by default. | bins : int or sequence, default 10 | Number of histogram bins to be used. If an integer is given, bins + 1 | bin edges are calculated and returned. If bins is a sequence, gives | bin edges, including left edge of first bin and right edge of last | bin. In this case, bins is returned unmodified. | backend : str, default None | Backend to use instead of the backend specified in the option | ``plotting.backend``. For instance, 'matplotlib'. Alternatively, to | specify the ``plotting.backend`` for the whole session, set | ``pd.options.plotting.backend``. | | .. versionadded:: 1.0.0 | | **kwargs | To be passed to the actual plotting function. | | Returns | ------- | matplotlib.AxesSubplot | A histogram plot. | | See Also | -------- | matplotlib.axes.Axes.hist : Plot a histogram using matplotlib. | | idxmax(self, axis=0, skipna=True, *args, **kwargs) | Return the row label of the maximum value. | | If multiple values equal the maximum, the first row label with that | value is returned. | | Parameters | ---------- | axis : int, default 0 | For compatibility with DataFrame.idxmax. Redundant for application | on Series. | skipna : bool, default True | Exclude NA/null values. If the entire Series is NA, the result | will be NA. | *args, **kwargs | Additional arguments and keywords have no effect but might be | accepted for compatibility with NumPy. | | Returns | ------- | Index | Label of the maximum value. | | Raises | ------ | ValueError | If the Series is empty. | | See Also | -------- | numpy.argmax : Return indices of the maximum values | along the given axis. | DataFrame.idxmax : Return index of first occurrence of maximum | over requested axis. | Series.idxmin : Return index *label* of the first occurrence | of minimum of values. | | Notes | ----- | This method is the Series version of ``ndarray.argmax``. This method | returns the label of the maximum, while ``ndarray.argmax`` returns | the position. To get the position, use ``series.values.argmax()``. | | Examples | -------- | >>> s = pd.Series(data=[1, None, 4, 3, 4], | ... index=['A', 'B', 'C', 'D', 'E']) | >>> s | A 1.0 | B NaN | C 4.0 | D 3.0 | E 4.0 | dtype: float64 | | >>> s.idxmax() | 'C' | | If `skipna` is False and there is an NA value in the data, | the function returns ``nan``. | | >>> s.idxmax(skipna=False) | nan | | idxmin(self, axis=0, skipna=True, *args, **kwargs) | Return the row label of the minimum value. | | If multiple values equal the minimum, the first row label with that | value is returned. | | Parameters | ---------- | axis : int, default 0 | For compatibility with DataFrame.idxmin. Redundant for application | on Series. | skipna : bool, default True | Exclude NA/null values. If the entire Series is NA, the result | will be NA. | *args, **kwargs | Additional arguments and keywords have no effect but might be | accepted for compatibility with NumPy. | | Returns | ------- | Index | Label of the minimum value. | | Raises | ------ | ValueError | If the Series is empty. | | See Also | -------- | numpy.argmin : Return indices of the minimum values | along the given axis. | DataFrame.idxmin : Return index of first occurrence of minimum | over requested axis. | Series.idxmax : Return index *label* of the first occurrence | of maximum of values. | | Notes | ----- | This method is the Series version of ``ndarray.argmin``. This method | returns the label of the minimum, while ``ndarray.argmin`` returns | the position. To get the position, use ``series.values.argmin()``. | | Examples | -------- | >>> s = pd.Series(data=[1, None, 4, 1], | ... index=['A', 'B', 'C', 'D']) | >>> s | A 1.0 | B NaN | C 4.0 | D 1.0 | dtype: float64 | | >>> s.idxmin() | 'A' | | If `skipna` is False and there is an NA value in the data, | the function returns ``nan``. | | >>> s.idxmin(skipna=False) | nan | | isin(self, values) | Check whether `values` are contained in Series. | | Return a boolean Series showing whether each element in the Series | matches an element in the passed sequence of `values` exactly. | | Parameters | ---------- | values : set or list-like | The sequence of values to test. Passing in a single string will | raise a ``TypeError``. Instead, turn a single string into a | list of one element. | | Returns | ------- | Series | Series of booleans indicating if each element is in values. | | Raises | ------ | TypeError | * If `values` is a string | | See Also | -------- | DataFrame.isin : Equivalent method on DataFrame. | | Examples | -------- | >>> s = pd.Series(['lama', 'cow', 'lama', 'beetle', 'lama', | ... 'hippo'], name='animal') | >>> s.isin(['cow', 'lama']) | 0 True | 1 True | 2 True | 3 False | 4 True | 5 False | Name: animal, dtype: bool | | Passing a single string as ``s.isin('lama')`` will raise an error. Use | a list of one element instead: | | >>> s.isin(['lama']) | 0 True | 1 False | 2 True | 3 False | 4 True | 5 False | Name: animal, dtype: bool | | isna(self) | Detect missing values. | | Return a boolean same-sized object indicating if the values are NA. | NA values, such as None or :attr:`numpy.NaN`, gets mapped to True | values. | Everything else gets mapped to False values. Characters such as empty | strings ``''`` or :attr:`numpy.inf` are not considered NA values | (unless you set ``pandas.options.mode.use_inf_as_na = True``). | | Returns | ------- | Series | Mask of bool values for each element in Series that | indicates whether an element is not an NA value. | | See Also | -------- | Series.isnull : Alias of isna. | Series.notna : Boolean inverse of isna. | Series.dropna : Omit axes labels with missing values. | isna : Top-level isna. | | Examples | -------- | Show which entries in a DataFrame are NA. | | >>> df = pd.DataFrame({'age': [5, 6, np.NaN], | ... 'born': [pd.NaT, pd.Timestamp('1939-05-27'), | ... pd.Timestamp('1940-04-25')], | ... 'name': ['Alfred', 'Batman', ''], | ... 'toy': [None, 'Batmobile', 'Joker']}) | >>> df | age born name toy | 0 5.0 NaT Alfred None | 1 6.0 1939-05-27 Batman Batmobile | 2 NaN 1940-04-25 Joker | | >>> df.isna() | age born name toy | 0 False True False True | 1 False False False False | 2 True False False False | | Show which entries in a Series are NA. | | >>> ser = pd.Series([5, 6, np.NaN]) | >>> ser | 0 5.0 | 1 6.0 | 2 NaN | dtype: float64 | | >>> ser.isna() | 0 False | 1 False | 2 True | dtype: bool | | isnull(self) | Detect missing values. | | Return a boolean same-sized object indicating if the values are NA. | NA values, such as None or :attr:`numpy.NaN`, gets mapped to True | values. | Everything else gets mapped to False values. Characters such as empty | strings ``''`` or :attr:`numpy.inf` are not considered NA values | (unless you set ``pandas.options.mode.use_inf_as_na = True``). | | Returns | ------- | Series | Mask of bool values for each element in Series that | indicates whether an element is not an NA value. | | See Also | -------- | Series.isnull : Alias of isna. | Series.notna : Boolean inverse of isna. | Series.dropna : Omit axes labels with missing values. | isna : Top-level isna. | | Examples | -------- | Show which entries in a DataFrame are NA. | | >>> df = pd.DataFrame({'age': [5, 6, np.NaN], | ... 'born': [pd.NaT, pd.Timestamp('1939-05-27'), | ... pd.Timestamp('1940-04-25')], | ... 'name': ['Alfred', 'Batman', ''], | ... 'toy': [None, 'Batmobile', 'Joker']}) | >>> df | age born name toy | 0 5.0 NaT Alfred None | 1 6.0 1939-05-27 Batman Batmobile | 2 NaN 1940-04-25 Joker | | >>> df.isna() | age born name toy | 0 False True False True | 1 False False False False | 2 True False False False | | Show which entries in a Series are NA. | | >>> ser = pd.Series([5, 6, np.NaN]) | >>> ser | 0 5.0 | 1 6.0 | 2 NaN | dtype: float64 | | >>> ser.isna() | 0 False | 1 False | 2 True | dtype: bool | | items(self) | Lazily iterate over (index, value) tuples. | | This method returns an iterable tuple (index, value). This is | convenient if you want to create a lazy iterator. | | Returns | ------- | iterable | Iterable of tuples containing the (index, value) pairs from a | Series. | | See Also | -------- | DataFrame.items : Iterate over (column name, Series) pairs. | DataFrame.iterrows : Iterate over DataFrame rows as (index, Series) pairs. | | Examples | -------- | >>> s = pd.Series(['A', 'B', 'C']) | >>> for index, value in s.items(): | ... print(f"Index : {index}, Value : {value}") | Index : 0, Value : A | Index : 1, Value : B | Index : 2, Value : C | | iteritems(self) | Lazily iterate over (index, value) tuples. | | This method returns an iterable tuple (index, value). This is | convenient if you want to create a lazy iterator. | | Returns | ------- | iterable | Iterable of tuples containing the (index, value) pairs from a | Series. | | See Also | -------- | DataFrame.items : Iterate over (column name, Series) pairs. | DataFrame.iterrows : Iterate over DataFrame rows as (index, Series) pairs. | | Examples | -------- | >>> s = pd.Series(['A', 'B', 'C']) | >>> for index, value in s.items(): | ... print(f"Index : {index}, Value : {value}") | Index : 0, Value : A | Index : 1, Value : B | Index : 2, Value : C | | keys(self) | Return alias for index. | | Returns | ------- | Index | Index of the Series. | | kurt(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs) | Return unbiased kurtosis over requested axis. | | Kurtosis obtained using Fisher's definition of | kurtosis (kurtosis of normal == 0.0). Normalized by N-1. | | Parameters | ---------- | axis : {index (0)} | Axis for the function to be applied on. | skipna : bool, default True | Exclude NA/null values when computing the result. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | numeric_only : bool, default None | Include only float, int, boolean columns. If None, will attempt to use | everything, then use only numeric data. Not implemented for Series. | **kwargs | Additional keyword arguments to be passed to the function. | | Returns | ------- | scalar or Series (if level specified) | | kurtosis = kurt(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs) | | le(self, other, level=None, fill_value=None, axis=0) | Return Less than or equal to of series and other, element-wise (binary operator `le`). | | Equivalent to ``series <= other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.None | | lt(self, other, level=None, fill_value=None, axis=0) | Return Less than of series and other, element-wise (binary operator `lt`). | | Equivalent to ``series < other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.None | | mad(self, axis=None, skipna=None, level=None) | Return the mean absolute deviation of the values for the requested axis. | | Parameters | ---------- | axis : {index (0)} | Axis for the function to be applied on. | skipna : bool, default True | Exclude NA/null values when computing the result. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | numeric_only : bool, default None | Include only float, int, boolean columns. If None, will attempt to use | everything, then use only numeric data. Not implemented for Series. | **kwargs | Additional keyword arguments to be passed to the function. | | Returns | ------- | scalar or Series (if level specified) | | map(self, arg, na_action=None) | Map values of Series according to input correspondence. | | Used for substituting each value in a Series with another value, | that may be derived from a function, a ``dict`` or | a :class:`Series`. | | Parameters | ---------- | arg : function, collections.abc.Mapping subclass or Series | Mapping correspondence. | na_action : {None, 'ignore'}, default None | If 'ignore', propagate NaN values, without passing them to the | mapping correspondence. | | Returns | ------- | Series | Same index as caller. | | See Also | -------- | Series.apply : For applying more complex functions on a Series. | DataFrame.apply : Apply a function row-/column-wise. | DataFrame.applymap : Apply a function elementwise on a whole DataFrame. | | Notes | ----- | When ``arg`` is a dictionary, values in Series that are not in the | dictionary (as keys) are converted to ``NaN``. However, if the | dictionary is a ``dict`` subclass that defines ``__missing__`` (i.e. | provides a method for default values), then this default is used | rather than ``NaN``. | | Examples | -------- | >>> s = pd.Series(['cat', 'dog', np.nan, 'rabbit']) | >>> s | 0 cat | 1 dog | 2 NaN | 3 rabbit | dtype: object | | ``map`` accepts a ``dict`` or a ``Series``. Values that are not found | in the ``dict`` are converted to ``NaN``, unless the dict has a default | value (e.g. ``defaultdict``): | | >>> s.map({'cat': 'kitten', 'dog': 'puppy'}) | 0 kitten | 1 puppy | 2 NaN | 3 NaN | dtype: object | | It also accepts a function: | | >>> s.map('I am a {}'.format) | 0 I am a cat | 1 I am a dog | 2 I am a nan | 3 I am a rabbit | dtype: object | | To avoid applying the function to missing values (and keep them as | ``NaN``) ``na_action='ignore'`` can be used: | | >>> s.map('I am a {}'.format, na_action='ignore') | 0 I am a cat | 1 I am a dog | 2 NaN | 3 I am a rabbit | dtype: object | | max(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs) | Return the maximum of the values for the requested axis. | | If you want the *index* of the maximum, use ``idxmax``. This is | the equivalent of the ``numpy.ndarray`` method ``argmax``. | | Parameters | ---------- | axis : {index (0)} | Axis for the function to be applied on. | skipna : bool, default True | Exclude NA/null values when computing the result. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | numeric_only : bool, default None | Include only float, int, boolean columns. If None, will attempt to use | everything, then use only numeric data. Not implemented for Series. | **kwargs | Additional keyword arguments to be passed to the function. | | Returns | ------- | scalar or Series (if level specified) | | See Also | -------- | Series.sum : Return the sum. | Series.min : Return the minimum. | Series.max : Return the maximum. | Series.idxmin : Return the index of the minimum. | Series.idxmax : Return the index of the maximum. | DataFrame.sum : Return the sum over the requested axis. | DataFrame.min : Return the minimum over the requested axis. | DataFrame.max : Return the maximum over the requested axis. | DataFrame.idxmin : Return the index of the minimum over the requested axis. | DataFrame.idxmax : Return the index of the maximum over the requested axis. | | Examples | -------- | >>> idx = pd.MultiIndex.from_arrays([ | ... ['warm', 'warm', 'cold', 'cold'], | ... ['dog', 'falcon', 'fish', 'spider']], | ... names=['blooded', 'animal']) | >>> s = pd.Series([4, 2, 0, 8], name='legs', index=idx) | >>> s | blooded animal | warm dog 4 | falcon 2 | cold fish 0 | spider 8 | Name: legs, dtype: int64 | | >>> s.max() | 8 | | Max using level names, as well as indices. | | >>> s.max(level='blooded') | blooded | warm 4 | cold 8 | Name: legs, dtype: int64 | | >>> s.max(level=0) | blooded | warm 4 | cold 8 | Name: legs, dtype: int64 | | mean(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs) | Return the mean of the values for the requested axis. | | Parameters | ---------- | axis : {index (0)} | Axis for the function to be applied on. | skipna : bool, default True | Exclude NA/null values when computing the result. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | numeric_only : bool, default None | Include only float, int, boolean columns. If None, will attempt to use | everything, then use only numeric data. Not implemented for Series. | **kwargs | Additional keyword arguments to be passed to the function. | | Returns | ------- | scalar or Series (if level specified) | | median(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs) | Return the median of the values for the requested axis. | | Parameters | ---------- | axis : {index (0)} | Axis for the function to be applied on. | skipna : bool, default True | Exclude NA/null values when computing the result. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | numeric_only : bool, default None | Include only float, int, boolean columns. If None, will attempt to use | everything, then use only numeric data. Not implemented for Series. | **kwargs | Additional keyword arguments to be passed to the function. | | Returns | ------- | scalar or Series (if level specified) | | memory_usage(self, index=True, deep=False) | Return the memory usage of the Series. | | The memory usage can optionally include the contribution of | the index and of elements of `object` dtype. | | Parameters | ---------- | index : bool, default True | Specifies whether to include the memory usage of the Series index. | deep : bool, default False | If True, introspect the data deeply by interrogating | `object` dtypes for system-level memory consumption, and include | it in the returned value. | | Returns | ------- | int | Bytes of memory consumed. | | See Also | -------- | numpy.ndarray.nbytes : Total bytes consumed by the elements of the | array. | DataFrame.memory_usage : Bytes consumed by a DataFrame. | | Examples | -------- | >>> s = pd.Series(range(3)) | >>> s.memory_usage() | 152 | | Not including the index gives the size of the rest of the data, which | is necessarily smaller: | | >>> s.memory_usage(index=False) | 24 | | The memory footprint of `object` values is ignored by default: | | >>> s = pd.Series(["a", "b"]) | >>> s.values | array(['a', 'b'], dtype=object) | >>> s.memory_usage() | 144 | >>> s.memory_usage(deep=True) | 260 | | min(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs) | Return the minimum of the values for the requested axis. | | If you want the *index* of the minimum, use ``idxmin``. This is | the equivalent of the ``numpy.ndarray`` method ``argmin``. | | Parameters | ---------- | axis : {index (0)} | Axis for the function to be applied on. | skipna : bool, default True | Exclude NA/null values when computing the result. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | numeric_only : bool, default None | Include only float, int, boolean columns. If None, will attempt to use | everything, then use only numeric data. Not implemented for Series. | **kwargs | Additional keyword arguments to be passed to the function. | | Returns | ------- | scalar or Series (if level specified) | | See Also | -------- | Series.sum : Return the sum. | Series.min : Return the minimum. | Series.max : Return the maximum. | Series.idxmin : Return the index of the minimum. | Series.idxmax : Return the index of the maximum. | DataFrame.sum : Return the sum over the requested axis. | DataFrame.min : Return the minimum over the requested axis. | DataFrame.max : Return the maximum over the requested axis. | DataFrame.idxmin : Return the index of the minimum over the requested axis. | DataFrame.idxmax : Return the index of the maximum over the requested axis. | | Examples | -------- | >>> idx = pd.MultiIndex.from_arrays([ | ... ['warm', 'warm', 'cold', 'cold'], | ... ['dog', 'falcon', 'fish', 'spider']], | ... names=['blooded', 'animal']) | >>> s = pd.Series([4, 2, 0, 8], name='legs', index=idx) | >>> s | blooded animal | warm dog 4 | falcon 2 | cold fish 0 | spider 8 | Name: legs, dtype: int64 | | >>> s.min() | 0 | | Min using level names, as well as indices. | | >>> s.min(level='blooded') | blooded | warm 2 | cold 0 | Name: legs, dtype: int64 | | >>> s.min(level=0) | blooded | warm 2 | cold 0 | Name: legs, dtype: int64 | | mod(self, other, level=None, fill_value=None, axis=0) | Return Modulo of series and other, element-wise (binary operator `mod`). | | Equivalent to ``series % other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.rmod | | Examples | -------- | >>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd']) | >>> a | a 1.0 | b 1.0 | c 1.0 | d NaN | dtype: float64 | >>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e']) | >>> b | a 1.0 | b NaN | d 1.0 | e NaN | dtype: float64 | >>> a.mod(b, fill_value=0) | a 0.0 | b NaN | c NaN | d 0.0 | e NaN | dtype: float64 | | mode(self, dropna=True) | Return the mode(s) of the dataset. | | Always returns Series even if only one value is returned. | | Parameters | ---------- | dropna : bool, default True | Don't consider counts of NaN/NaT. | | .. versionadded:: 0.24.0 | | Returns | ------- | Series | Modes of the Series in sorted order. | | mul(self, other, level=None, fill_value=None, axis=0) | Return Multiplication of series and other, element-wise (binary operator `mul`). | | Equivalent to ``series * other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.rmul | | Examples | -------- | >>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd']) | >>> a | a 1.0 | b 1.0 | c 1.0 | d NaN | dtype: float64 | >>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e']) | >>> b | a 1.0 | b NaN | d 1.0 | e NaN | dtype: float64 | >>> a.multiply(b, fill_value=0) | a 1.0 | b 0.0 | c 0.0 | d 0.0 | e NaN | dtype: float64 | | multiply = mul(self, other, level=None, fill_value=None, axis=0) | | ne(self, other, level=None, fill_value=None, axis=0) | Return Not equal to of series and other, element-wise (binary operator `ne`). | | Equivalent to ``series != other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.None | | nlargest(self, n=5, keep='first') | Return the largest `n` elements. | | Parameters | ---------- | n : int, default 5 | Return this many descending sorted values. | keep : {'first', 'last', 'all'}, default 'first' | When there are duplicate values that cannot all fit in a | Series of `n` elements: | | - ``first`` : return the first `n` occurrences in order | of appearance. | - ``last`` : return the last `n` occurrences in reverse | order of appearance. | - ``all`` : keep all occurrences. This can result in a Series of | size larger than `n`. | | Returns | ------- | Series | The `n` largest values in the Series, sorted in decreasing order. | | See Also | -------- | Series.nsmallest: Get the `n` smallest elements. | Series.sort_values: Sort Series by values. | Series.head: Return the first `n` rows. | | Notes | ----- | Faster than ``.sort_values(ascending=False).head(n)`` for small `n` | relative to the size of the ``Series`` object. | | Examples | -------- | >>> countries_population = {"Italy": 59000000, "France": 65000000, | ... "Malta": 434000, "Maldives": 434000, | ... "Brunei": 434000, "Iceland": 337000, | ... "Nauru": 11300, "Tuvalu": 11300, | ... "Anguilla": 11300, "Monserat": 5200} | >>> s = pd.Series(countries_population) | >>> s | Italy 59000000 | France 65000000 | Malta 434000 | Maldives 434000 | Brunei 434000 | Iceland 337000 | Nauru 11300 | Tuvalu 11300 | Anguilla 11300 | Monserat 5200 | dtype: int64 | | The `n` largest elements where ``n=5`` by default. | | >>> s.nlargest() | France 65000000 | Italy 59000000 | Malta 434000 | Maldives 434000 | Brunei 434000 | dtype: int64 | | The `n` largest elements where ``n=3``. Default `keep` value is 'first' | so Malta will be kept. | | >>> s.nlargest(3) | France 65000000 | Italy 59000000 | Malta 434000 | dtype: int64 | | The `n` largest elements where ``n=3`` and keeping the last duplicates. | Brunei will be kept since it is the last with value 434000 based on | the index order. | | >>> s.nlargest(3, keep='last') | France 65000000 | Italy 59000000 | Brunei 434000 | dtype: int64 | | The `n` largest elements where ``n=3`` with all duplicates kept. Note | that the returned Series has five elements due to the three duplicates. | | >>> s.nlargest(3, keep='all') | France 65000000 | Italy 59000000 | Malta 434000 | Maldives 434000 | Brunei 434000 | dtype: int64 | | notna(self) | Detect existing (non-missing) values. | | Return a boolean same-sized object indicating if the values are not NA. | Non-missing values get mapped to True. Characters such as empty | strings ``''`` or :attr:`numpy.inf` are not considered NA values | (unless you set ``pandas.options.mode.use_inf_as_na = True``). | NA values, such as None or :attr:`numpy.NaN`, get mapped to False | values. | | Returns | ------- | Series | Mask of bool values for each element in Series that | indicates whether an element is not an NA value. | | See Also | -------- | Series.notnull : Alias of notna. | Series.isna : Boolean inverse of notna. | Series.dropna : Omit axes labels with missing values. | notna : Top-level notna. | | Examples | -------- | Show which entries in a DataFrame are not NA. | | >>> df = pd.DataFrame({'age': [5, 6, np.NaN], | ... 'born': [pd.NaT, pd.Timestamp('1939-05-27'), | ... pd.Timestamp('1940-04-25')], | ... 'name': ['Alfred', 'Batman', ''], | ... 'toy': [None, 'Batmobile', 'Joker']}) | >>> df | age born name toy | 0 5.0 NaT Alfred None | 1 6.0 1939-05-27 Batman Batmobile | 2 NaN 1940-04-25 Joker | | >>> df.notna() | age born name toy | 0 True False True False | 1 True True True True | 2 False True True True | | Show which entries in a Series are not NA. | | >>> ser = pd.Series([5, 6, np.NaN]) | >>> ser | 0 5.0 | 1 6.0 | 2 NaN | dtype: float64 | | >>> ser.notna() | 0 True | 1 True | 2 False | dtype: bool | | notnull(self) | Detect existing (non-missing) values. | | Return a boolean same-sized object indicating if the values are not NA. | Non-missing values get mapped to True. Characters such as empty | strings ``''`` or :attr:`numpy.inf` are not considered NA values | (unless you set ``pandas.options.mode.use_inf_as_na = True``). | NA values, such as None or :attr:`numpy.NaN`, get mapped to False | values. | | Returns | ------- | Series | Mask of bool values for each element in Series that | indicates whether an element is not an NA value. | | See Also | -------- | Series.notnull : Alias of notna. | Series.isna : Boolean inverse of notna. | Series.dropna : Omit axes labels with missing values. | notna : Top-level notna. | | Examples | -------- | Show which entries in a DataFrame are not NA. | | >>> df = pd.DataFrame({'age': [5, 6, np.NaN], | ... 'born': [pd.NaT, pd.Timestamp('1939-05-27'), | ... pd.Timestamp('1940-04-25')], | ... 'name': ['Alfred', 'Batman', ''], | ... 'toy': [None, 'Batmobile', 'Joker']}) | >>> df | age born name toy | 0 5.0 NaT Alfred None | 1 6.0 1939-05-27 Batman Batmobile | 2 NaN 1940-04-25 Joker | | >>> df.notna() | age born name toy | 0 True False True False | 1 True True True True | 2 False True True True | | Show which entries in a Series are not NA. | | >>> ser = pd.Series([5, 6, np.NaN]) | >>> ser | 0 5.0 | 1 6.0 | 2 NaN | dtype: float64 | | >>> ser.notna() | 0 True | 1 True | 2 False | dtype: bool | | nsmallest(self, n=5, keep='first') | Return the smallest `n` elements. | | Parameters | ---------- | n : int, default 5 | Return this many ascending sorted values. | keep : {'first', 'last', 'all'}, default 'first' | When there are duplicate values that cannot all fit in a | Series of `n` elements: | | - ``first`` : return the first `n` occurrences in order | of appearance. | - ``last`` : return the last `n` occurrences in reverse | order of appearance. | - ``all`` : keep all occurrences. This can result in a Series of | size larger than `n`. | | Returns | ------- | Series | The `n` smallest values in the Series, sorted in increasing order. | | See Also | -------- | Series.nlargest: Get the `n` largest elements. | Series.sort_values: Sort Series by values. | Series.head: Return the first `n` rows. | | Notes | ----- | Faster than ``.sort_values().head(n)`` for small `n` relative to | the size of the ``Series`` object. | | Examples | -------- | >>> countries_population = {"Italy": 59000000, "France": 65000000, | ... "Brunei": 434000, "Malta": 434000, | ... "Maldives": 434000, "Iceland": 337000, | ... "Nauru": 11300, "Tuvalu": 11300, | ... "Anguilla": 11300, "Monserat": 5200} | >>> s = pd.Series(countries_population) | >>> s | Italy 59000000 | France 65000000 | Brunei 434000 | Malta 434000 | Maldives 434000 | Iceland 337000 | Nauru 11300 | Tuvalu 11300 | Anguilla 11300 | Monserat 5200 | dtype: int64 | | The `n` smallest elements where ``n=5`` by default. | | >>> s.nsmallest() | Monserat 5200 | Nauru 11300 | Tuvalu 11300 | Anguilla 11300 | Iceland 337000 | dtype: int64 | | The `n` smallest elements where ``n=3``. Default `keep` value is | 'first' so Nauru and Tuvalu will be kept. | | >>> s.nsmallest(3) | Monserat 5200 | Nauru 11300 | Tuvalu 11300 | dtype: int64 | | The `n` smallest elements where ``n=3`` and keeping the last | duplicates. Anguilla and Tuvalu will be kept since they are the last | with value 11300 based on the index order. | | >>> s.nsmallest(3, keep='last') | Monserat 5200 | Anguilla 11300 | Tuvalu 11300 | dtype: int64 | | The `n` smallest elements where ``n=3`` with all duplicates kept. Note | that the returned Series has four elements due to the three duplicates. | | >>> s.nsmallest(3, keep='all') | Monserat 5200 | Nauru 11300 | Tuvalu 11300 | Anguilla 11300 | dtype: int64 | | pow(self, other, level=None, fill_value=None, axis=0) | Return Exponential power of series and other, element-wise (binary operator `pow`). | | Equivalent to ``series ** other``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.rpow | | Examples | -------- | >>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd']) | >>> a | a 1.0 | b 1.0 | c 1.0 | d NaN | dtype: float64 | >>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e']) | >>> b | a 1.0 | b NaN | d 1.0 | e NaN | dtype: float64 | >>> a.pow(b, fill_value=0) | a 1.0 | b 1.0 | c 1.0 | d 0.0 | e NaN | dtype: float64 | | prod(self, axis=None, skipna=None, level=None, numeric_only=None, min_count=0, **kwargs) | Return the product of the values for the requested axis. | | Parameters | ---------- | axis : {index (0)} | Axis for the function to be applied on. | skipna : bool, default True | Exclude NA/null values when computing the result. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | numeric_only : bool, default None | Include only float, int, boolean columns. If None, will attempt to use | everything, then use only numeric data. Not implemented for Series. | min_count : int, default 0 | The required number of valid values to perform the operation. If fewer than | ``min_count`` non-NA values are present the result will be NA. | | .. versionadded:: 0.22.0 | | Added with the default being 0. This means the sum of an all-NA | or empty Series is 0, and the product of an all-NA or empty | Series is 1. | **kwargs | Additional keyword arguments to be passed to the function. | | Returns | ------- | scalar or Series (if level specified) | | Examples | -------- | By default, the product of an empty or all-NA Series is ``1`` | | >>> pd.Series([]).prod() | 1.0 | | This can be controlled with the ``min_count`` parameter | | >>> pd.Series([]).prod(min_count=1) | nan | | Thanks to the ``skipna`` parameter, ``min_count`` handles all-NA and | empty series identically. | | >>> pd.Series([np.nan]).prod() | 1.0 | | >>> pd.Series([np.nan]).prod(min_count=1) | nan | | product = prod(self, axis=None, skipna=None, level=None, numeric_only=None, min_count=0, **kwargs) | | quantile(self, q=0.5, interpolation='linear') | Return value at the given quantile. | | Parameters | ---------- | q : float or array-like, default 0.5 (50% quantile) | The quantile(s) to compute, which can lie in range: 0 <= q <= 1. | interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'} | This optional parameter specifies the interpolation method to use, | when the desired quantile lies between two data points `i` and `j`: | | * linear: `i + (j - i) * fraction`, where `fraction` is the | fractional part of the index surrounded by `i` and `j`. | * lower: `i`. | * higher: `j`. | * nearest: `i` or `j` whichever is nearest. | * midpoint: (`i` + `j`) / 2. | | Returns | ------- | float or Series | If ``q`` is an array, a Series will be returned where the | index is ``q`` and the values are the quantiles, otherwise | a float will be returned. | | See Also | -------- | core.window.Rolling.quantile | numpy.percentile | | Examples | -------- | >>> s = pd.Series([1, 2, 3, 4]) | >>> s.quantile(.5) | 2.5 | >>> s.quantile([.25, .5, .75]) | 0.25 1.75 | 0.50 2.50 | 0.75 3.25 | dtype: float64 | | radd(self, other, level=None, fill_value=None, axis=0) | Return Addition of series and other, element-wise (binary operator `radd`). | | Equivalent to ``other + series``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.add | | Examples | -------- | >>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd']) | >>> a | a 1.0 | b 1.0 | c 1.0 | d NaN | dtype: float64 | >>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e']) | >>> b | a 1.0 | b NaN | d 1.0 | e NaN | dtype: float64 | >>> a.add(b, fill_value=0) | a 2.0 | b 1.0 | c 1.0 | d 1.0 | e NaN | dtype: float64 | | ravel(self, order='C') | Return the flattened underlying data as an ndarray. | | Returns | ------- | numpy.ndarray or ndarray-like | Flattened data of the Series. | | See Also | -------- | numpy.ndarray.ravel | | rdiv = rtruediv(self, other, level=None, fill_value=None, axis=0) | | rdivmod(self, other, level=None, fill_value=None, axis=0) | Return Integer division and modulo of series and other, element-wise (binary operator `rdivmod`). | | Equivalent to ``other divmod series``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.divmod | | reindex(self, index=None, **kwargs) | Conform Series to new index with optional filling logic. | | Places NA/NaN in locations having no value in the previous index. A new object | is produced unless the new index is equivalent to the current one and | ``copy=False``. | | Parameters | ---------- | | index : array-like, optional | New labels / index to conform to, should be specified using | keywords. Preferably an Index object to avoid duplicating data. | | method : {None, 'backfill'/'bfill', 'pad'/'ffill', 'nearest'} | Method to use for filling holes in reindexed DataFrame. | Please note: this is only applicable to DataFrames/Series with a | monotonically increasing/decreasing index. | | * None (default): don't fill gaps | * pad / ffill: Propagate last valid observation forward to next | valid. | * backfill / bfill: Use next valid observation to fill gap. | * nearest: Use nearest valid observations to fill gap. | | copy : bool, default True | Return a new object, even if the passed indexes are the same. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | fill_value : scalar, default np.NaN | Value to use for missing values. Defaults to NaN, but can be any | "compatible" value. | limit : int, default None | Maximum number of consecutive elements to forward or backward fill. | tolerance : optional | Maximum distance between original and new labels for inexact | matches. The values of the index at the matching locations most | satisfy the equation ``abs(index[indexer] - target) <= tolerance``. | | Tolerance may be a scalar value, which applies the same tolerance | to all values, or list-like, which applies variable tolerance per | element. List-like includes list, tuple, array, Series, and must be | the same size as the index and its dtype must exactly match the | index's type. | | .. versionadded:: 0.21.0 (list-like tolerance) | | Returns | ------- | Series with changed index. | | See Also | -------- | DataFrame.set_index : Set row labels. | DataFrame.reset_index : Remove row labels or move them to new columns. | DataFrame.reindex_like : Change to same indices as other DataFrame. | | Examples | -------- | | ``DataFrame.reindex`` supports two calling conventions | | * ``(index=index_labels, columns=column_labels, ...)`` | * ``(labels, axis={'index', 'columns'}, ...)`` | | We *highly* recommend using keyword arguments to clarify your | intent. | | Create a dataframe with some fictional data. | | >>> index = ['Firefox', 'Chrome', 'Safari', 'IE10', 'Konqueror'] | >>> df = pd.DataFrame({'http_status': [200, 200, 404, 404, 301], | ... 'response_time': [0.04, 0.02, 0.07, 0.08, 1.0]}, | ... index=index) | >>> df | http_status response_time | Firefox 200 0.04 | Chrome 200 0.02 | Safari 404 0.07 | IE10 404 0.08 | Konqueror 301 1.00 | | Create a new index and reindex the dataframe. By default | values in the new index that do not have corresponding | records in the dataframe are assigned ``NaN``. | | >>> new_index = ['Safari', 'Iceweasel', 'Comodo Dragon', 'IE10', | ... 'Chrome'] | >>> df.reindex(new_index) | http_status response_time | Safari 404.0 0.07 | Iceweasel NaN NaN | Comodo Dragon NaN NaN | IE10 404.0 0.08 | Chrome 200.0 0.02 | | We can fill in the missing values by passing a value to | the keyword ``fill_value``. Because the index is not monotonically | increasing or decreasing, we cannot use arguments to the keyword | ``method`` to fill the ``NaN`` values. | | >>> df.reindex(new_index, fill_value=0) | http_status response_time | Safari 404 0.07 | Iceweasel 0 0.00 | Comodo Dragon 0 0.00 | IE10 404 0.08 | Chrome 200 0.02 | | >>> df.reindex(new_index, fill_value='missing') | http_status response_time | Safari 404 0.07 | Iceweasel missing missing | Comodo Dragon missing missing | IE10 404 0.08 | Chrome 200 0.02 | | We can also reindex the columns. | | >>> df.reindex(columns=['http_status', 'user_agent']) | http_status user_agent | Firefox 200 NaN | Chrome 200 NaN | Safari 404 NaN | IE10 404 NaN | Konqueror 301 NaN | | Or we can use "axis-style" keyword arguments | | >>> df.reindex(['http_status', 'user_agent'], axis="columns") | http_status user_agent | Firefox 200 NaN | Chrome 200 NaN | Safari 404 NaN | IE10 404 NaN | Konqueror 301 NaN | | To further illustrate the filling functionality in | ``reindex``, we will create a dataframe with a | monotonically increasing index (for example, a sequence | of dates). | | >>> date_index = pd.date_range('1/1/2010', periods=6, freq='D') | >>> df2 = pd.DataFrame({"prices": [100, 101, np.nan, 100, 89, 88]}, | ... index=date_index) | >>> df2 | prices | 2010-01-01 100.0 | 2010-01-02 101.0 | 2010-01-03 NaN | 2010-01-04 100.0 | 2010-01-05 89.0 | 2010-01-06 88.0 | | Suppose we decide to expand the dataframe to cover a wider | date range. | | >>> date_index2 = pd.date_range('12/29/2009', periods=10, freq='D') | >>> df2.reindex(date_index2) | prices | 2009-12-29 NaN | 2009-12-30 NaN | 2009-12-31 NaN | 2010-01-01 100.0 | 2010-01-02 101.0 | 2010-01-03 NaN | 2010-01-04 100.0 | 2010-01-05 89.0 | 2010-01-06 88.0 | 2010-01-07 NaN | | The index entries that did not have a value in the original data frame | (for example, '2009-12-29') are by default filled with ``NaN``. | If desired, we can fill in the missing values using one of several | options. | | For example, to back-propagate the last valid value to fill the ``NaN`` | values, pass ``bfill`` as an argument to the ``method`` keyword. | | >>> df2.reindex(date_index2, method='bfill') | prices | 2009-12-29 100.0 | 2009-12-30 100.0 | 2009-12-31 100.0 | 2010-01-01 100.0 | 2010-01-02 101.0 | 2010-01-03 NaN | 2010-01-04 100.0 | 2010-01-05 89.0 | 2010-01-06 88.0 | 2010-01-07 NaN | | Please note that the ``NaN`` value present in the original dataframe | (at index value 2010-01-03) will not be filled by any of the | value propagation schemes. This is because filling while reindexing | does not look at dataframe values, but only compares the original and | desired indexes. If you do want to fill in the ``NaN`` values present | in the original dataframe, use the ``fillna()`` method. | | See the :ref:`user guide <basics.reindexing>` for more. | | rename(self, index=None, *, axis=None, copy=True, inplace=False, level=None, errors='ignore') | Alter Series index labels or name. | | Function / dict values must be unique (1-to-1). Labels not contained in | a dict / Series will be left as-is. Extra labels listed don't throw an | error. | | Alternatively, change ``Series.name`` with a scalar value. | | See the :ref:`user guide <basics.rename>` for more. | | Parameters | ---------- | axis : {0 or "index"} | Unused. Accepted for compatability with DataFrame method only. | index : scalar, hashable sequence, dict-like or function, optional | Functions or dict-like are transformations to apply to | the index. | Scalar or hashable sequence-like will alter the ``Series.name`` | attribute. | | **kwargs | Additional keyword arguments passed to the function. Only the | "inplace" keyword is used. | | Returns | ------- | Series | Series with index labels or name altered. | | See Also | -------- | DataFrame.rename : Corresponding DataFrame method. | Series.rename_axis : Set the name of the axis. | | Examples | -------- | >>> s = pd.Series([1, 2, 3]) | >>> s | 0 1 | 1 2 | 2 3 | dtype: int64 | >>> s.rename("my_name") # scalar, changes Series.name | 0 1 | 1 2 | 2 3 | Name: my_name, dtype: int64 | >>> s.rename(lambda x: x ** 2) # function, changes labels | 0 1 | 1 2 | 4 3 | dtype: int64 | >>> s.rename({1: 3, 2: 5}) # mapping, changes labels | 0 1 | 3 2 | 5 3 | dtype: int64 | | reorder_levels(self, order) | Rearrange index levels using input order. | | May not drop or duplicate levels. | | Parameters | ---------- | order : list of int representing new level order | Reference level by number or key. | | Returns | ------- | type of caller (new object) | | repeat(self, repeats, axis=None) | Repeat elements of a Series. | | Returns a new Series where each element of the current Series | is repeated consecutively a given number of times. | | Parameters | ---------- | repeats : int or array of ints | The number of repetitions for each element. This should be a | non-negative integer. Repeating 0 times will return an empty | Series. | axis : None | Must be ``None``. Has no effect but is accepted for compatibility | with numpy. | | Returns | ------- | Series | Newly created Series with repeated elements. | | See Also | -------- | Index.repeat : Equivalent function for Index. | numpy.repeat : Similar method for :class:`numpy.ndarray`. | | Examples | -------- | >>> s = pd.Series(['a', 'b', 'c']) | >>> s | 0 a | 1 b | 2 c | dtype: object | >>> s.repeat(2) | 0 a | 0 a | 1 b | 1 b | 2 c | 2 c | dtype: object | >>> s.repeat([1, 2, 3]) | 0 a | 1 b | 1 b | 2 c | 2 c | 2 c | dtype: object | | replace(self, to_replace=None, value=None, inplace=False, limit=None, regex=False, method='pad') | Replace values given in `to_replace` with `value`. | | Values of the Series are replaced with other values dynamically. | This differs from updating with ``.loc`` or ``.iloc``, which require | you to specify a location to update with some value. | | Parameters | ---------- | to_replace : str, regex, list, dict, Series, int, float, or None | How to find the values that will be replaced. | | * numeric, str or regex: | | - numeric: numeric values equal to `to_replace` will be | replaced with `value` | - str: string exactly matching `to_replace` will be replaced | with `value` | - regex: regexs matching `to_replace` will be replaced with | `value` | | * list of str, regex, or numeric: | | - First, if `to_replace` and `value` are both lists, they | **must** be the same length. | - Second, if ``regex=True`` then all of the strings in **both** | lists will be interpreted as regexs otherwise they will match | directly. This doesn't matter much for `value` since there | are only a few possible substitution regexes you can use. | - str, regex and numeric rules apply as above. | | * dict: | | - Dicts can be used to specify different replacement values | for different existing values. For example, | ``{'a': 'b', 'y': 'z'}`` replaces the value 'a' with 'b' and | 'y' with 'z'. To use a dict in this way the `value` | parameter should be `None`. | - For a DataFrame a dict can specify that different values | should be replaced in different columns. For example, | ``{'a': 1, 'b': 'z'}`` looks for the value 1 in column 'a' | and the value 'z' in column 'b' and replaces these values | with whatever is specified in `value`. The `value` parameter | should not be ``None`` in this case. You can treat this as a | special case of passing two lists except that you are | specifying the column to search in. | - For a DataFrame nested dictionaries, e.g., | ``{'a': {'b': np.nan}}``, are read as follows: look in column | 'a' for the value 'b' and replace it with NaN. The `value` | parameter should be ``None`` to use a nested dict in this | way. You can nest regular expressions as well. Note that | column names (the top-level dictionary keys in a nested | dictionary) **cannot** be regular expressions. | | * None: | | - This means that the `regex` argument must be a string, | compiled regular expression, or list, dict, ndarray or | Series of such elements. If `value` is also ``None`` then | this **must** be a nested dictionary or Series. | | See the examples section for examples of each of these. | value : scalar, dict, list, str, regex, default None | Value to replace any values matching `to_replace` with. | For a DataFrame a dict of values can be used to specify which | value to use for each column (columns not in the dict will not be | filled). Regular expressions, strings and lists or dicts of such | objects are also allowed. | inplace : bool, default False | If True, in place. Note: this will modify any | other views on this object (e.g. a column from a DataFrame). | Returns the caller if this is True. | limit : int, default None | Maximum size gap to forward or backward fill. | regex : bool or same types as `to_replace`, default False | Whether to interpret `to_replace` and/or `value` as regular | expressions. If this is ``True`` then `to_replace` *must* be a | string. Alternatively, this could be a regular expression or a | list, dict, or array of regular expressions in which case | `to_replace` must be ``None``. | method : {'pad', 'ffill', 'bfill', `None`} | The method to use when for replacement, when `to_replace` is a | scalar, list or tuple and `value` is ``None``. | | .. versionchanged:: 0.23.0 | Added to DataFrame. | | Returns | ------- | Series | Object after replacement. | | Raises | ------ | AssertionError | * If `regex` is not a ``bool`` and `to_replace` is not | ``None``. | TypeError | * If `to_replace` is a ``dict`` and `value` is not a ``list``, | ``dict``, ``ndarray``, or ``Series`` | * If `to_replace` is ``None`` and `regex` is not compilable | into a regular expression or is a list, dict, ndarray, or | Series. | * When replacing multiple ``bool`` or ``datetime64`` objects and | the arguments to `to_replace` does not match the type of the | value being replaced | ValueError | * If a ``list`` or an ``ndarray`` is passed to `to_replace` and | `value` but they are not the same length. | | See Also | -------- | Series.fillna : Fill NA values. | Series.where : Replace values based on boolean condition. | Series.str.replace : Simple string replacement. | | Notes | ----- | * Regex substitution is performed under the hood with ``re.sub``. The | rules for substitution for ``re.sub`` are the same. | * Regular expressions will only substitute on strings, meaning you | cannot provide, for example, a regular expression matching floating | point numbers and expect the columns in your frame that have a | numeric dtype to be matched. However, if those floating point | numbers *are* strings, then you can do this. | * This method has *a lot* of options. You are encouraged to experiment | and play with this method to gain intuition about how it works. | * When dict is used as the `to_replace` value, it is like | key(s) in the dict are the to_replace part and | value(s) in the dict are the value parameter. | | Examples | -------- | | **Scalar `to_replace` and `value`** | | >>> s = pd.Series([0, 1, 2, 3, 4]) | >>> s.replace(0, 5) | 0 5 | 1 1 | 2 2 | 3 3 | 4 4 | dtype: int64 | | >>> df = pd.DataFrame({'A': [0, 1, 2, 3, 4], | ... 'B': [5, 6, 7, 8, 9], | ... 'C': ['a', 'b', 'c', 'd', 'e']}) | >>> df.replace(0, 5) | A B C | 0 5 5 a | 1 1 6 b | 2 2 7 c | 3 3 8 d | 4 4 9 e | | **List-like `to_replace`** | | >>> df.replace([0, 1, 2, 3], 4) | A B C | 0 4 5 a | 1 4 6 b | 2 4 7 c | 3 4 8 d | 4 4 9 e | | >>> df.replace([0, 1, 2, 3], [4, 3, 2, 1]) | A B C | 0 4 5 a | 1 3 6 b | 2 2 7 c | 3 1 8 d | 4 4 9 e | | >>> s.replace([1, 2], method='bfill') | 0 0 | 1 3 | 2 3 | 3 3 | 4 4 | dtype: int64 | | **dict-like `to_replace`** | | >>> df.replace({0: 10, 1: 100}) | A B C | 0 10 5 a | 1 100 6 b | 2 2 7 c | 3 3 8 d | 4 4 9 e | | >>> df.replace({'A': 0, 'B': 5}, 100) | A B C | 0 100 100 a | 1 1 6 b | 2 2 7 c | 3 3 8 d | 4 4 9 e | | >>> df.replace({'A': {0: 100, 4: 400}}) | A B C | 0 100 5 a | 1 1 6 b | 2 2 7 c | 3 3 8 d | 4 400 9 e | | **Regular expression `to_replace`** | | >>> df = pd.DataFrame({'A': ['bat', 'foo', 'bait'], | ... 'B': ['abc', 'bar', 'xyz']}) | >>> df.replace(to_replace=r'^ba.$', value='new', regex=True) | A B | 0 new abc | 1 foo new | 2 bait xyz | | >>> df.replace({'A': r'^ba.$'}, {'A': 'new'}, regex=True) | A B | 0 new abc | 1 foo bar | 2 bait xyz | | >>> df.replace(regex=r'^ba.$', value='new') | A B | 0 new abc | 1 foo new | 2 bait xyz | | >>> df.replace(regex={r'^ba.$': 'new', 'foo': 'xyz'}) | A B | 0 new abc | 1 xyz new | 2 bait xyz | | >>> df.replace(regex=[r'^ba.$', 'foo'], value='new') | A B | 0 new abc | 1 new new | 2 bait xyz | | Note that when replacing multiple ``bool`` or ``datetime64`` objects, | the data types in the `to_replace` parameter must match the data | type of the value being replaced: | | >>> df = pd.DataFrame({'A': [True, False, True], | ... 'B': [False, True, False]}) | >>> df.replace({'a string': 'new value', True: False}) # raises | Traceback (most recent call last): | ... | TypeError: Cannot compare types 'ndarray(dtype=bool)' and 'str' | | This raises a ``TypeError`` because one of the ``dict`` keys is not of | the correct type for replacement. | | Compare the behavior of ``s.replace({'a': None})`` and | ``s.replace('a', None)`` to understand the peculiarities | of the `to_replace` parameter: | | >>> s = pd.Series([10, 'a', 'a', 'b', 'a']) | | When one uses a dict as the `to_replace` value, it is like the | value(s) in the dict are equal to the `value` parameter. | ``s.replace({'a': None})`` is equivalent to | ``s.replace(to_replace={'a': None}, value=None, method=None)``: | | >>> s.replace({'a': None}) | 0 10 | 1 None | 2 None | 3 b | 4 None | dtype: object | | When ``value=None`` and `to_replace` is a scalar, list or | tuple, `replace` uses the method parameter (default 'pad') to do the | replacement. So this is why the 'a' values are being replaced by 10 | in rows 1 and 2 and 'b' in row 4 in this case. | The command ``s.replace('a', None)`` is actually equivalent to | ``s.replace(to_replace='a', value=None, method='pad')``: | | >>> s.replace('a', None) | 0 10 | 1 10 | 2 10 | 3 b | 4 b | dtype: object | | reset_index(self, level=None, drop=False, name=None, inplace=False) | Generate a new DataFrame or Series with the index reset. | | This is useful when the index needs to be treated as a column, or | when the index is meaningless and needs to be reset to the default | before another operation. | | Parameters | ---------- | level : int, str, tuple, or list, default optional | For a Series with a MultiIndex, only remove the specified levels | from the index. Removes all levels by default. | drop : bool, default False | Just reset the index, without inserting it as a column in | the new DataFrame. | name : object, optional | The name to use for the column containing the original Series | values. Uses ``self.name`` by default. This argument is ignored | when `drop` is True. | inplace : bool, default False | Modify the Series in place (do not create a new object). | | Returns | ------- | Series or DataFrame | When `drop` is False (the default), a DataFrame is returned. | The newly created columns will come first in the DataFrame, | followed by the original Series values. | When `drop` is True, a `Series` is returned. | In either case, if ``inplace=True``, no value is returned. | | See Also | -------- | DataFrame.reset_index: Analogous function for DataFrame. | | Examples | -------- | >>> s = pd.Series([1, 2, 3, 4], name='foo', | ... index=pd.Index(['a', 'b', 'c', 'd'], name='idx')) | | Generate a DataFrame with default index. | | >>> s.reset_index() | idx foo | 0 a 1 | 1 b 2 | 2 c 3 | 3 d 4 | | To specify the name of the new column use `name`. | | >>> s.reset_index(name='values') | idx values | 0 a 1 | 1 b 2 | 2 c 3 | 3 d 4 | | To generate a new Series with the default set `drop` to True. | | >>> s.reset_index(drop=True) | 0 1 | 1 2 | 2 3 | 3 4 | Name: foo, dtype: int64 | | To update the Series in place, without generating a new one | set `inplace` to True. Note that it also requires ``drop=True``. | | >>> s.reset_index(inplace=True, drop=True) | >>> s | 0 1 | 1 2 | 2 3 | 3 4 | Name: foo, dtype: int64 | | The `level` parameter is interesting for Series with a multi-level | index. | | >>> arrays = [np.array(['bar', 'bar', 'baz', 'baz']), | ... np.array(['one', 'two', 'one', 'two'])] | >>> s2 = pd.Series( | ... range(4), name='foo', | ... index=pd.MultiIndex.from_arrays(arrays, | ... names=['a', 'b'])) | | To remove a specific level from the Index, use `level`. | | >>> s2.reset_index(level='a') | a foo | b | one bar 0 | two bar 1 | one baz 2 | two baz 3 | | If `level` is not set, all levels are removed from the Index. | | >>> s2.reset_index() | a b foo | 0 bar one 0 | 1 bar two 1 | 2 baz one 2 | 3 baz two 3 | | rfloordiv(self, other, level=None, fill_value=None, axis=0) | Return Integer division of series and other, element-wise (binary operator `rfloordiv`). | | Equivalent to ``other // series``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.floordiv | | Examples | -------- | >>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd']) | >>> a | a 1.0 | b 1.0 | c 1.0 | d NaN | dtype: float64 | >>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e']) | >>> b | a 1.0 | b NaN | d 1.0 | e NaN | dtype: float64 | >>> a.floordiv(b, fill_value=0) | a 1.0 | b NaN | c NaN | d 0.0 | e NaN | dtype: float64 | | rmod(self, other, level=None, fill_value=None, axis=0) | Return Modulo of series and other, element-wise (binary operator `rmod`). | | Equivalent to ``other % series``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.mod | | Examples | -------- | >>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd']) | >>> a | a 1.0 | b 1.0 | c 1.0 | d NaN | dtype: float64 | >>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e']) | >>> b | a 1.0 | b NaN | d 1.0 | e NaN | dtype: float64 | >>> a.mod(b, fill_value=0) | a 0.0 | b NaN | c NaN | d 0.0 | e NaN | dtype: float64 | | rmul(self, other, level=None, fill_value=None, axis=0) | Return Multiplication of series and other, element-wise (binary operator `rmul`). | | Equivalent to ``other * series``, but with support to substitute a fill_value for | missing data in one of the inputs. | | Parameters | ---------- | other : Series or scalar value | fill_value : None or float value, default None (NaN) | Fill existing missing (NaN) values, and any new element needed for | successful Series alignment, with this value before computation. | If data in both corresponding Series locations is missing | the result will be missing. | level : int or name | Broadcast across a level, matching Index values on the | passed MultiIndex level. | | Returns | ------- | Series | The result of the operation. | | See Also | -------- | Series.mul | | Examples | -------- | >>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd']) | >>> a | a 1.0 | b 1.0 | c 1.0 | d NaN | dtype: float64 | >>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e']) | >>> b | a 1.0 | b NaN | d 1.0 | e NaN | dtype: float64 | >>> a.multiply(b, fill_value=0) | a 1.0 | b 0.0 | c 0.0 | d 0.0 | e NaN | dtype: float64 | | rolling(self, window, min_periods=None, center=False, win_type=None, on=None, axis=0, closed=None) | Provide rolling window calculations. | | Parameters | ---------- | window : int, offset, or BaseIndexer subclass | Size of the moving window. This is the number of observations used for | calculating the statistic. Each window will be a fixed size. | | If its an offset then this will be the time period of each window. Each | window will be a variable sized based on the observations included in | the time-period. This is only valid for datetimelike indexes. | | If a BaseIndexer subclass is passed, calculates the window boundaries | based on the defined ``get_window_bounds`` method. Additional rolling | keyword arguments, namely `min_periods`, `center`, and | `closed` will be passed to `get_window_bounds`. | min_periods : int, default None | Minimum number of observations in window required to have a value | (otherwise result is NA). For a window that is specified by an offset, | `min_periods` will default to 1. Otherwise, `min_periods` will default | to the size of the window. | center : bool, default False | Set the labels at the center of the window. | win_type : str, default None | Provide a window type. If ``None``, all points are evenly weighted. | See the notes below for further information. | on : str, optional | For a DataFrame, a datetime-like column or MultiIndex level on which | to calculate the rolling window, rather than the DataFrame's index. | Provided integer column is ignored and excluded from result since | an integer index is not used to calculate the rolling window. | axis : int or str, default 0 | closed : str, default None | Make the interval closed on the 'right', 'left', 'both' or | 'neither' endpoints. | For offset-based windows, it defaults to 'right'. | For fixed windows, defaults to 'both'. Remaining cases not implemented | for fixed windows. | | Returns | ------- | a Window or Rolling sub-classed for the particular operation | | See Also | -------- | expanding : Provides expanding transformations. | ewm : Provides exponential weighted functions. | | Notes | ----- | By default, the result is set to the right edge of the window. This can be | changed to the center of the window by setting ``center=True``. | | To learn more about the offsets & frequency strings, please see `this link | <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__. | | The recognized win_types are: | | * ``boxcar`` | * ``triang`` | * ``blackman`` | * ``hamming`` | * ``bartlett`` | * ``parzen`` | * ``bohman`` | * ``blackmanharris`` | * ``nuttall`` | * ``barthann`` | * ``kaiser`` (needs beta) | * ``gaussian`` (needs std) | * ``general_gaussian`` (needs power, width) | * ``slepian`` (needs width) | * ``exponential`` (needs tau), center is set to None. | | If ``win_type=None`` all points are evenly weighted. To learn more about | different window types see `scipy.signal window functions | <https://docs.scipy.org/doc/scipy/reference/signal.html#window-functions>`__. | | Examples | -------- | | >>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]}) | >>> df | B | 0 0.0 | 1 1.0 | 2 2.0 | 3 NaN | 4 4.0 | | Rolling sum with a window length of 2, using the 'triang' | window type. | | >>> df.rolling(2, win_type='triang').sum() | B | 0 NaN | 1 0.5 | 2 1.5 | 3 NaN | 4 NaN | | Rolling sum with a window length of 2, using the 'gaussian' | window type (note how we need to specify std). | | >>> df.rolling(2, win_type='gaussian').sum(std=3) | B | 0 NaN | 1 0.986207 | 2 2.958621 | 3 NaN | 4 NaN | | Rolling sum with a window length of 2, min_periods defaults | to the window length. | | >>> df.rolling(2).sum() | B | 0 NaN | 1 1.0 | 2 3.0 | 3 NaN | 4 NaN | | Same as above, but explicitly set the min_periods | | >>> df.rolling(2, min_periods=1).sum() | B | 0 0.0 | 1 1.0 | 2 3.0 | 3 2.0 | 4 4.0 | | A ragged (meaning not-a-regular frequency), time-indexed DataFrame | | >>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]}, | ... index = [pd.Timestamp('20130101 09:00:00'), | ... pd.Timestamp('20130101 09:00:02'), | ... pd.Timestamp('20130101 09:00:03'), | ... pd.Timestamp('20130101 09:00:05'), | ... pd.Timestamp('20130101 09:00:06')]) | | >>> df | B | 2013-01-01 09:00:00 0.0 | 2013-01-01 09:00:02 1.0 | 2013-01-01 09:00:03 2.0 | 2013-01-01 09:00:05 NaN | 2013-01-01 09:00:06 4.0 | | Contrasting to an integer rolling window, this will roll a variable | length window corresponding to the time period. | The default for min_periods is 1. | | >>> df.rolling('2s').sum() | B | 2013-01-01 09:00:00 0.0 | 2013-01-01 09:00:02 1.