0 | 2013-01-01 09:00:03 3.0 | 2013-01-01 09:00:05 NaN | 2013-01-01 09:00:06 4.0 | | round(self, decimals=0, *args, **kwargs) | Round each value in a Series to the given number of decimals. | | Parameters | ---------- | decimals : int, default 0 | Number of decimal places to round to. If decimals is negative, | it specifies the number of positions to the left of the decimal point. | | Returns | ------- | Series | Rounded values of the Series. | | See Also | -------- | numpy.around : Round values of an np.array. | DataFrame.round : Round values of a DataFrame. | | Examples | -------- | >>> s = pd.Series([0.1, 1.3, 2.7]) | >>> s.round() | 0 0.0 | 1 1.0 | 2 3.0 | dtype: float64 | | rpow(self, other, level=None, fill_value=None, axis=0) | Return Exponential power of series and other, element-wise (binary operator `rpow`). | | 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.pow | | 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 | | rsub(self, other, level=None, fill_value=None, axis=0) | Return Subtraction of series and other, element-wise (binary operator `rsub`). | | 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.sub | | 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.subtract(b, fill_value=0) | a 0.0 | b 1.0 | c 1.0 | d -1.0 | e NaN | dtype: float64 | | rtruediv(self, other, level=None, fill_value=None, axis=0) | Return Floating division of series and other, element-wise (binary operator `rtruediv`). | | 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.truediv | | 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.divide(b, fill_value=0) | a 1.0 | b inf | c inf | d 0.0 | e NaN | dtype: float64 | | searchsorted(self, value, side='left', sorter=None) | Find indices where elements should be inserted to maintain order. | | Find the indices into a sorted Series `self` such that, if the | corresponding elements in `value` were inserted before the indices, | the order of `self` would be preserved. | | .. note:: | | The Series *must* be monotonically sorted, otherwise | wrong locations will likely be returned. Pandas does *not* | check this for you. | | Parameters | ---------- | value : array_like | Values to insert into `self`. | side : {'left', 'right'}, optional | If 'left', the index of the first suitable location found is given. | If 'right', return the last such index. If there is no suitable | index, return either 0 or N (where N is the length of `self`). | sorter : 1-D array_like, optional | Optional array of integer indices that sort `self` into ascending | order. They are typically the result of ``np.argsort``. | | Returns | ------- | int or array of int | A scalar or array of insertion points with the | same shape as `value`. | | .. versionchanged:: 0.24.0 | If `value` is a scalar, an int is now always returned. | Previously, scalar inputs returned an 1-item array for | :class:`Series` and :class:`Categorical`. | | See Also | -------- | sort_values | numpy.searchsorted | | Notes | ----- | Binary search is used to find the required insertion points. | | Examples | -------- | | >>> x = pd.Series([1, 2, 3]) | >>> x | 0 1 | 1 2 | 2 3 | dtype: int64 | | >>> x.searchsorted(4) | 3 | | >>> x.searchsorted([0, 4]) | array([0, 3]) | | >>> x.searchsorted([1, 3], side='left') | array([0, 2]) | | >>> x.searchsorted([1, 3], side='right') | array([1, 3]) | | >>> x = pd.Categorical(['apple', 'bread', 'bread', | 'cheese', 'milk'], ordered=True) | [apple, bread, bread, cheese, milk] | Categories (4, object): [apple < bread < cheese < milk] | | >>> x.searchsorted('bread') | 1 | | >>> x.searchsorted(['bread'], side='right') | array([3]) | | If the values are not monotonically sorted, wrong locations | may be returned: | | >>> x = pd.Series([2, 1, 3]) | >>> x.searchsorted(1) | 0 # wrong result, correct would be 1 | | sem(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs) | Return unbiased standard error of the mean over requested axis. | | Normalized by N-1 by default. This can be changed using the ddof argument | | Parameters | ---------- | axis : {index (0)} | skipna : bool, default True | Exclude NA/null values. If an entire row/column is NA, the result | will be NA. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | ddof : int, default 1 | Delta Degrees of Freedom. The divisor used in calculations is N - ddof, | where N represents the number of elements. | 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. | | Returns | ------- | scalar or Series (if level specified) | | shift(self, periods=1, freq=None, axis=0, fill_value=None) | Shift index by desired number of periods with an optional time `freq`. | | When `freq` is not passed, shift the index without realigning the data. | If `freq` is passed (in this case, the index must be date or datetime, | or it will raise a `NotImplementedError`), the index will be | increased using the periods and the `freq`. | | Parameters | ---------- | periods : int | Number of periods to shift. Can be positive or negative. | freq : DateOffset, tseries.offsets, timedelta, or str, optional | Offset to use from the tseries module or time rule (e.g. 'EOM'). | If `freq` is specified then the index values are shifted but the | data is not realigned. That is, use `freq` if you would like to | extend the index when shifting and preserve the original data. | axis : {0 or 'index', 1 or 'columns', None}, default None | Shift direction. | fill_value : object, optional | The scalar value to use for newly introduced missing values. | the default depends on the dtype of `self`. | For numeric data, ``np.nan`` is used. | For datetime, timedelta, or period data, etc. :attr:`NaT` is used. | For extension dtypes, ``self.dtype.na_value`` is used. | | .. versionchanged:: 0.24.0 | | Returns | ------- | Series | Copy of input object, shifted. | | See Also | -------- | Index.shift : Shift values of Index. | DatetimeIndex.shift : Shift values of DatetimeIndex. | PeriodIndex.shift : Shift values of PeriodIndex. | tshift : Shift the time index, using the index's frequency if | available. | | Examples | -------- | >>> df = pd.DataFrame({'Col1': [10, 20, 15, 30, 45], | ... 'Col2': [13, 23, 18, 33, 48], | ... 'Col3': [17, 27, 22, 37, 52]}) | | >>> df.shift(periods=3) | Col1 Col2 Col3 | 0 NaN NaN NaN | 1 NaN NaN NaN | 2 NaN NaN NaN | 3 10.0 13.0 17.0 | 4 20.0 23.0 27.0 | | >>> df.shift(periods=1, axis='columns') | Col1 Col2 Col3 | 0 NaN 10.0 13.0 | 1 NaN 20.0 23.0 | 2 NaN 15.0 18.0 | 3 NaN 30.0 33.0 | 4 NaN 45.0 48.0 | | >>> df.shift(periods=3, fill_value=0) | Col1 Col2 Col3 | 0 0 0 0 | 1 0 0 0 | 2 0 0 0 | 3 10 13 17 | 4 20 23 27 | | skew(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs) | Return unbiased skew over requested axis. | | 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) | | sort_index(self, axis=0, level=None, ascending=True, inplace=False, kind='quicksort', na_position='last', sort_remaining=True, ignore_index: bool = False) | Sort Series by index labels. | | Returns a new Series sorted by label if `inplace` argument is | ``False``, otherwise updates the original series and returns None. | | Parameters | ---------- | axis : int, default 0 | Axis to direct sorting. This can only be 0 for Series. | level : int, optional | If not None, sort on values in specified index level(s). | ascending : bool, default true | Sort ascending vs. descending. | inplace : bool, default False | If True, perform operation in-place. | kind : {'quicksort', 'mergesort', 'heapsort'}, default 'quicksort' | Choice of sorting algorithm. See also :func:`numpy.sort` for more | information. 'mergesort' is the only stable algorithm. For | DataFrames, this option is only applied when sorting on a single | column or label. | na_position : {'first', 'last'}, default 'last' | If 'first' puts NaNs at the beginning, 'last' puts NaNs at the end. | Not implemented for MultiIndex. | sort_remaining : bool, default True | If True and sorting by level and index is multilevel, sort by other | levels too (in order) after sorting by specified level. | ignore_index : bool, default False | If True, the resulting axis will be labeled 0, 1, …, n - 1. | | .. versionadded:: 1.0.0 | | Returns | ------- | Series | The original Series sorted by the labels. | | See Also | -------- | DataFrame.sort_index: Sort DataFrame by the index. | DataFrame.sort_values: Sort DataFrame by the value. | Series.sort_values : Sort Series by the value. | | Examples | -------- | >>> s = pd.Series(['a', 'b', 'c', 'd'], index=[3, 2, 1, 4]) | >>> s.sort_index() | 1 c | 2 b | 3 a | 4 d | dtype: object | | Sort Descending | | >>> s.sort_index(ascending=False) | 4 d | 3 a | 2 b | 1 c | dtype: object | | Sort Inplace | | >>> s.sort_index(inplace=True) | >>> s | 1 c | 2 b | 3 a | 4 d | dtype: object | | By default NaNs are put at the end, but use `na_position` to place | them at the beginning | | >>> s = pd.Series(['a', 'b', 'c', 'd'], index=[3, 2, 1, np.nan]) | >>> s.sort_index(na_position='first') | NaN d | 1.0 c | 2.0 b | 3.0 a | dtype: object | | Specify index level to sort | | >>> arrays = [np.array(['qux', 'qux', 'foo', 'foo', | ... 'baz', 'baz', 'bar', 'bar']), | ... np.array(['two', 'one', 'two', 'one', | ... 'two', 'one', 'two', 'one'])] | >>> s = pd.Series([1, 2, 3, 4, 5, 6, 7, 8], index=arrays) | >>> s.sort_index(level=1) | bar one 8 | baz one 6 | foo one 4 | qux one 2 | bar two 7 | baz two 5 | foo two 3 | qux two 1 | dtype: int64 | | Does not sort by remaining levels when sorting by levels | | >>> s.sort_index(level=1, sort_remaining=False) | qux one 2 | foo one 4 | baz one 6 | bar one 8 | qux two 1 | foo two 3 | baz two 5 | bar two 7 | dtype: int64 | | sort_values(self, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False) | Sort by the values. | | Sort a Series in ascending or descending order by some | criterion. | | Parameters | ---------- | axis : {0 or 'index'}, default 0 | Axis to direct sorting. The value 'index' is accepted for | compatibility with DataFrame.sort_values. | ascending : bool, default True | If True, sort values in ascending order, otherwise descending. | inplace : bool, default False | If True, perform operation in-place. | kind : {'quicksort', 'mergesort' or 'heapsort'}, default 'quicksort' | Choice of sorting algorithm. See also :func:`numpy.sort` for more | information. 'mergesort' is the only stable algorithm. | na_position : {'first' or 'last'}, default 'last' | Argument 'first' puts NaNs at the beginning, 'last' puts NaNs at | the end. | ignore_index : bool, default False | If True, the resulting axis will be labeled 0, 1, …, n - 1. | | .. versionadded:: 1.0.0 | | Returns | ------- | Series | Series ordered by values. | | See Also | -------- | Series.sort_index : Sort by the Series indices. | DataFrame.sort_values : Sort DataFrame by the values along either axis. | DataFrame.sort_index : Sort DataFrame by indices. | | Examples | -------- | >>> s = pd.Series([np.nan, 1, 3, 10, 5]) | >>> s | 0 NaN | 1 1.0 | 2 3.0 | 3 10.0 | 4 5.0 | dtype: float64 | | Sort values ascending order (default behaviour) | | >>> s.sort_values(ascending=True) | 1 1.0 | 2 3.0 | 4 5.0 | 3 10.0 | 0 NaN | dtype: float64 | | Sort values descending order | | >>> s.sort_values(ascending=False) | 3 10.0 | 4 5.0 | 2 3.0 | 1 1.0 | 0 NaN | dtype: float64 | | Sort values inplace | | >>> s.sort_values(ascending=False, inplace=True) | >>> s | 3 10.0 | 4 5.0 | 2 3.0 | 1 1.0 | 0 NaN | dtype: float64 | | Sort values putting NAs first | | >>> s.sort_values(na_position='first') | 0 NaN | 1 1.0 | 2 3.0 | 4 5.0 | 3 10.0 | dtype: float64 | | Sort a series of strings | | >>> s = pd.Series(['z', 'b', 'd', 'a', 'c']) | >>> s | 0 z | 1 b | 2 d | 3 a | 4 c | dtype: object | | >>> s.sort_values() | 3 a | 1 b | 4 c | 2 d | 0 z | dtype: object | | std(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs) | Return sample standard deviation over requested axis. | | Normalized by N-1 by default. This can be changed using the ddof argument | | Parameters | ---------- | axis : {index (0)} | skipna : bool, default True | Exclude NA/null values. If an entire row/column is NA, the result | will be NA. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | ddof : int, default 1 | Delta Degrees of Freedom. The divisor used in calculations is N - ddof, | where N represents the number of elements. | 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. | | Returns | ------- | scalar or Series (if level specified) | | sub(self, other, level=None, fill_value=None, axis=0) | Return Subtraction of series and other, element-wise (binary operator `sub`). | | 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.rsub | | 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.subtract(b, fill_value=0) | a 0.0 | b 1.0 | c 1.0 | d -1.0 | e NaN | dtype: float64 | | subtract = sub(self, other, level=None, fill_value=None, axis=0) | | sum(self, axis=None, skipna=None, level=None, numeric_only=None, min_count=0, **kwargs) | Return the sum of the values for the requested axis. | | This is equivalent to the method ``numpy.sum``. | | 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) | | 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.sum() | 14 | | Sum using level names, as well as indices. | | >>> s.sum(level='blooded') | blooded | warm 6 | cold 8 | Name: legs, dtype: int64 | | >>> s.sum(level=0) | blooded | warm 6 | cold 8 | Name: legs, dtype: int64 | | By default, the sum of an empty or all-NA Series is ``0``. | | >>> pd.Series([]).sum() # min_count=0 is the default | 0.0 | | This can be controlled with the ``min_count`` parameter. For example, if | you'd like the sum of an empty series to be NaN, pass ``min_count=1``. | | >>> pd.Series([]).sum(min_count=1) | nan | | Thanks to the ``skipna`` parameter, ``min_count`` handles all-NA and | empty series identically. | | >>> pd.Series([np.nan]).sum() | 0.0 | | >>> pd.Series([np.nan]).sum(min_count=1) | nan | | swaplevel(self, i=-2, j=-1, copy=True) | Swap levels i and j in a :class:`MultiIndex`. | | Default is to swap the two innermost levels of the index. | | Parameters | ---------- | i, j : int, str | Level of the indices to be swapped. Can pass level name as string. | copy : bool, default True | Whether to copy underlying data. | | Returns | ------- | Series | Series with levels swapped in MultiIndex. | | take(self, indices, axis=0, is_copy=None, **kwargs) -> 'Series' | Return the elements in the given *positional* indices along an axis. | | This means that we are not indexing according to actual values in | the index attribute of the object. We are indexing according to the | actual position of the element in the object. | | Parameters | ---------- | indices : array-like | An array of ints indicating which positions to take. | axis : {0 or 'index', 1 or 'columns', None}, default 0 | The axis on which to select elements. ``0`` means that we are | selecting rows, ``1`` means that we are selecting columns. | is_copy : bool | Before pandas 1.0, ``is_copy=False`` can be specified to ensure | that the return value is an actual copy. Starting with pandas 1.0, | ``take`` always returns a copy, and the keyword is therefore | deprecated. | | .. deprecated:: 1.0.0 | **kwargs | For compatibility with :meth:`numpy.take`. Has no effect on the | output. | | Returns | ------- | taken : same type as caller | An array-like containing the elements taken from the object. | | See Also | -------- | DataFrame.loc : Select a subset of a DataFrame by labels. | DataFrame.iloc : Select a subset of a DataFrame by positions. | numpy.take : Take elements from an array along an axis. | | Examples | -------- | >>> df = pd.DataFrame([('falcon', 'bird', 389.0), | ... ('parrot', 'bird', 24.0), | ... ('lion', 'mammal', 80.5), | ... ('monkey', 'mammal', np.nan)], | ... columns=['name', 'class', 'max_speed'], | ... index=[0, 2, 3, 1]) | >>> df | name class max_speed | 0 falcon bird 389.0 | 2 parrot bird 24.0 | 3 lion mammal 80.5 | 1 monkey mammal NaN | | Take elements at positions 0 and 3 along the axis 0 (default). | | Note how the actual indices selected (0 and 1) do not correspond to | our selected indices 0 and 3. That's because we are selecting the 0th | and 3rd rows, not rows whose indices equal 0 and 3. | | >>> df.take([0, 3]) | name class max_speed | 0 falcon bird 389.0 | 1 monkey mammal NaN | | Take elements at indices 1 and 2 along the axis 1 (column selection). | | >>> df.take([1, 2], axis=1) | class max_speed | 0 bird 389.0 | 2 bird 24.0 | 3 mammal 80.5 | 1 mammal NaN | | We may take elements using negative integers for positive indices, | starting from the end of the object, just like with Python lists. | | >>> df.take([-1, -2]) | name class max_speed | 1 monkey mammal NaN | 3 lion mammal 80.5 | | to_dict(self, into=<class 'dict'>) | Convert Series to {label -> value} dict or dict-like object. | | Parameters | ---------- | into : class, default dict | The collections.abc.Mapping subclass to use as the return | object. Can be the actual class or an empty | instance of the mapping type you want. If you want a | collections.defaultdict, you must pass it initialized. | | .. versionadded:: 0.21.0 | | Returns | ------- | collections.abc.Mapping | Key-value representation of Series. | | Examples | -------- | >>> s = pd.Series([1, 2, 3, 4]) | >>> s.to_dict() | {0: 1, 1: 2, 2: 3, 3: 4} | >>> from collections import OrderedDict, defaultdict | >>> s.to_dict(OrderedDict) | OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)]) | >>> dd = defaultdict(list) | >>> s.to_dict(dd) | defaultdict(<class 'list'>, {0: 1, 1: 2, 2: 3, 3: 4}) | | to_frame(self, name=None) | Convert Series to DataFrame. | | Parameters | ---------- | name : object, default None | The passed name should substitute for the series name (if it has | one). | | Returns | ------- | DataFrame | DataFrame representation of Series. | | Examples | -------- | >>> s = pd.Series(["a", "b", "c"], | ... name="vals") | >>> s.to_frame() | vals | 0 a | 1 b | 2 c | | to_markdown(self, buf: Union[IO[str], NoneType] = None, mode: Union[str, NoneType] = None, **kwargs) -> Union[str, NoneType] | Print Series in Markdown-friendly format. | | .. versionadded:: 1.0.0 | | Parameters | ---------- | buf : writable buffer, defaults to sys.stdout | Where to send the output. By default, the output is printed to | sys.stdout. Pass a writable buffer if you need to further process | the output. | mode : str, optional | Mode in which file is opened. | **kwargs | These parameters will be passed to `tabulate`. | | Returns | ------- | str | Series in Markdown-friendly format. | | Examples | -------- | >>> s = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal") | >>> print(s.to_markdown()) | | | animal | | |---:|:---------| | | 0 | elk | | | 1 | pig | | | 2 | dog | | | 3 | quetzal | | | to_period(self, freq=None, copy=True) | Convert Series from DatetimeIndex to PeriodIndex with desired | frequency (inferred from index if not passed). | | Parameters | ---------- | freq : str, default None | Frequency associated with the PeriodIndex. | copy : bool, default True | Whether or not to return a copy. | | Returns | ------- | Series | Series with index converted to PeriodIndex. | | to_string(self, buf=None, na_rep='NaN', float_format=None, header=True, index=True, length=False, dtype=False, name=False, max_rows=None, min_rows=None) | Render a string representation of the Series. | | Parameters | ---------- | buf : StringIO-like, optional | Buffer to write to. | na_rep : str, optional | String representation of NaN to use, default 'NaN'. | float_format : one-parameter function, optional | Formatter function to apply to columns' elements if they are | floats, default None. | header : bool, default True | Add the Series header (index name). | index : bool, optional | Add index (row) labels, default True. | length : bool, default False | Add the Series length. | dtype : bool, default False | Add the Series dtype. | name : bool, default False | Add the Series name if not None. | max_rows : int, optional | Maximum number of rows to show before truncating. If None, show | all. | min_rows : int, optional | The number of rows to display in a truncated repr (when number | of rows is above `max_rows`). | | Returns | ------- | str or None | String representation of Series if ``buf=None``, otherwise None. | | to_timestamp(self, freq=None, how='start', copy=True) | Cast to DatetimeIndex of Timestamps, at *beginning* of period. | | Parameters | ---------- | freq : str, default frequency of PeriodIndex | Desired frequency. | how : {'s', 'e', 'start', 'end'} | Convention for converting period to timestamp; start of period | vs. end. | copy : bool, default True | Whether or not to return a copy. | | Returns | ------- | Series with DatetimeIndex | | transform(self, func, axis=0, *args, **kwargs) | Call ``func`` on self producing a Series with transformed values. | | Produced Series will have same axis length as self. | | Parameters | ---------- | func : function, str, list or dict | Function to use for transforming 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.exp. 'sqrt']`` | - 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 | ------- | Series | A Series that must have the same length as self. | | Raises | ------ | ValueError : If the returned Series has a different length than self. | | See Also | -------- | Series.agg : Only perform aggregating type operations. | Series.apply : Invoke function on a Series. | | Examples | -------- | >>> df = pd.DataFrame({'A': range(3), 'B': range(1, 4)}) | >>> df | A B | 0 0 1 | 1 1 2 | 2 2 3 | >>> df.transform(lambda x: x + 1) | A B | 0 1 2 | 1 2 3 | 2 3 4 | | Even though the resulting Series must have the same length as the | input Series, it is possible to provide several input functions: | | >>> s = pd.Series(range(3)) | >>> s | 0 0 | 1 1 | 2 2 | dtype: int64 | >>> s.transform([np.sqrt, np.exp]) | sqrt exp | 0 0.000000 1.000000 | 1 1.000000 2.718282 | 2 1.414214 7.389056 | | truediv(self, other, level=None, fill_value=None, axis=0) | Return Floating division of series and other, element-wise (binary operator `truediv`). | | 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.rtruediv | | 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.divide(b, fill_value=0) | a 1.0 | b inf | c inf | d 0.0 | e NaN | dtype: float64 | | unique(self) | Return unique values of Series object. | | Uniques are returned in order of appearance. Hash table-based unique, | therefore does NOT sort. | | Returns | ------- | ndarray or ExtensionArray | The unique values returned as a NumPy array. See Notes. | | See Also | -------- | unique : Top-level unique method for any 1-d array-like object. | Index.unique : Return Index with unique values from an Index object. | | Notes | ----- | Returns the unique values as a NumPy array. In case of an | extension-array backed Series, a new | :class:`~api.extensions.ExtensionArray` of that type with just | the unique values is returned. This includes | | * Categorical | * Period | * Datetime with Timezone | * Interval | * Sparse | * IntegerNA | | See Examples section. | | Examples | -------- | >>> pd.Series([2, 1, 3, 3], name='A').unique() | array([2, 1, 3]) | | >>> pd.Series([pd.Timestamp('2016-01-01') for _ in range(3)]).unique() | array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]') | | >>> pd.Series([pd.Timestamp('2016-01-01', tz='US/Eastern') | ... for _ in range(3)]).unique() | <DatetimeArray> | ['2016-01-01 00:00:00-05:00'] | Length: 1, dtype: datetime64[ns, US/Eastern] | | An unordered Categorical will return categories in the order of | appearance. | | >>> pd.Series(pd.Categorical(list('baabc'))).unique() | [b, a, c] | Categories (3, object): [b, a, c] | | An ordered Categorical preserves the category ordering. | | >>> pd.Series(pd.Categorical(list('baabc'), categories=list('abc'), | ... ordered=True)).unique() | [b, a, c] | Categories (3, object): [a < b < c] | | unstack(self, level=-1, fill_value=None) | Unstack, a.k.a. pivot, Series with MultiIndex to produce DataFrame. | The level involved will automatically get sorted. | | Parameters | ---------- | level : int, str, or list of these, default last level | Level(s) to unstack, can pass level name. | fill_value : scalar value, default None | Value to use when replacing NaN values. | | Returns | ------- | DataFrame | Unstacked Series. | | Examples | -------- | >>> s = pd.Series([1, 2, 3, 4], | ... index=pd.MultiIndex.from_product([['one', 'two'], | ... ['a', 'b']])) | >>> s | one a 1 | b 2 | two a 3 | b 4 | dtype: int64 | | >>> s.unstack(level=-1) | a b | one 1 2 | two 3 4 | | >>> s.unstack(level=0) | one two | a 1 3 | b 2 4 | | update(self, other) | Modify Series in place using non-NA values from passed | Series. Aligns on index. | | Parameters | ---------- | other : Series | | Examples | -------- | >>> s = pd.Series([1, 2, 3]) | >>> s.update(pd.Series([4, 5, 6])) | >>> s | 0 4 | 1 5 | 2 6 | dtype: int64 | | >>> s = pd.Series(['a', 'b', 'c']) | >>> s.update(pd.Series(['d', 'e'], index=[0, 2])) | >>> s | 0 d | 1 b | 2 e | dtype: object | | >>> s = pd.Series([1, 2, 3]) | >>> s.update(pd.Series([4, 5, 6, 7, 8])) | >>> s | 0 4 | 1 5 | 2 6 | dtype: int64 | | If ``other`` contains NaNs the corresponding values are not updated | in the original Series. | | >>> s = pd.Series([1, 2, 3]) | >>> s.update(pd.Series([4, np.nan, 6])) | >>> s | 0 4 | 1 2 | 2 6 | dtype: int64 | | var(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs) | Return unbiased variance over requested axis. | | Normalized by N-1 by default. This can be changed using the ddof argument | | Parameters | ---------- | axis : {index (0)} | skipna : bool, default True | Exclude NA/null values. If an entire row/column is NA, the result | will be NA. | level : int or level name, default None | If the axis is a MultiIndex (hierarchical), count along a | particular level, collapsing into a scalar. | ddof : int, default 1 | Delta Degrees of Freedom. The divisor used in calculations is N - ddof, | where N represents the number of elements. | 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. | | Returns | ------- | scalar or Series (if level specified) | | view(self, dtype=None) | Create a new view of the Series. | | This function will return a new Series with a view of the same | underlying values in memory, optionally reinterpreted with a new data | type. The new data type must preserve the same size in bytes as to not | cause index misalignment. | | Parameters | ---------- | dtype : data type | Data type object or one of their string representations. | | Returns | ------- | Series | A new Series object as a view of the same data in memory. | | See Also | -------- | numpy.ndarray.view : Equivalent numpy function to create a new view of | the same data in memory. | | Notes | ----- | Series are instantiated with ``dtype=float64`` by default. While | ``numpy.ndarray.view()`` will return a view with the same data type as | the original array, ``Series.view()`` (without specified dtype) | will try using ``float64`` and may fail if the original data type size | in bytes is not the same. | | Examples | -------- | >>> s = pd.Series([-2, -1, 0, 1, 2], dtype='int8') | >>> s | 0 -2 | 1 -1 | 2 0 | 3 1 | 4 2 | dtype: int8 | | The 8 bit signed integer representation of `-1` is `0b11111111`, but | the same bytes represent 255 if read as an 8 bit unsigned integer: | | >>> us = s.view('uint8') | >>> us | 0 254 | 1 255 | 2 0 | 3 1 | 4 2 | dtype: uint8 | | The views share the same underlying values: | | >>> us[0] = 128 | >>> s | 0 -128 | 1 -1 | 2 0 | 3 1 | 4 2 | dtype: int8 | | ---------------------------------------------------------------------- | Readonly properties defined here: | | array | The ExtensionArray of the data backing this Series or Index. | | .. versionadded:: 0.24.0 | | Returns | ------- | ExtensionArray | An ExtensionArray of the values stored within. For extension | types, this is the actual array. For NumPy native types, this | is a thin (no copy) wrapper around :class:`numpy.ndarray`. | | ``.array`` differs ``.values`` which may require converting the | data to a different form. | | See Also | -------- | Index.to_numpy : Similar method that always returns a NumPy array. | Series.to_numpy : Similar method that always returns a NumPy array. | | Notes | ----- | This table lays out the different array types for each extension | dtype within pandas. | | ================== ============================= | dtype array type | ================== ============================= | category Categorical | period PeriodArray | interval IntervalArray | IntegerNA IntegerArray | string StringArray | boolean BooleanArray | datetime64[ns, tz] DatetimeArray | ================== ============================= | | For any 3rd-party extension types, the array type will be an | ExtensionArray. | | For all remaining dtypes ``.array`` will be a | :class:`arrays.NumpyExtensionArray` wrapping the actual ndarray | stored within. If you absolutely need a NumPy array (possibly with | copying / coercing data), then use :meth:`Series.to_numpy` instead. | | Examples | -------- | | For regular NumPy types like int, and float, a PandasArray | is returned. | | >>> pd.Series([1, 2, 3]).array | <PandasArray> | [1, 2, 3] | Length: 3, dtype: int64 | | For extension types, like Categorical, the actual ExtensionArray | is returned | | >>> ser = pd.Series(pd.Categorical(['a', 'b', 'a'])) | >>> ser.array | [a, b, a] | Categories (2, object): [a, b] | | axes | Return a list of the row axis labels. | | dtype | Return the dtype object of the underlying data. | | dtypes | Return the dtype object of the underlying data. | | hasnans | Return if I have any nans; enables various perf speedups. | | values | Return Series as ndarray or ndarray-like depending on the dtype. | | .. warning:: | | We recommend using :attr:`Series.array` or | :meth:`Series.to_numpy`, depending on whether you need | a reference to the underlying data or a NumPy array. | | Returns | ------- | numpy.ndarray or ndarray-like | | See Also | -------- | Series.array : Reference to the underlying data. | Series.to_numpy : A NumPy array representing the underlying data. | | Examples | -------- | >>> pd.Series([1, 2, 3]).values | array([1, 2, 3]) | | >>> pd.Series(list('aabc')).values | array(['a', 'a', 'b', 'c'], dtype=object) | | >>> pd.Series(list('aabc')).astype('category').values | [a, a, b, c] | Categories (3, object): [a, b, c] | | Timezone aware datetime data is converted to UTC: | | >>> pd.Series(pd.date_range('20130101', periods=3, | ... tz='US/Eastern')).values | array(['2013-01-01T05:00:00.000000000', | '2013-01-02T05:00:00.000000000', | '2013-01-03T05:00:00.000000000'], dtype='datetime64[ns]') | | ---------------------------------------------------------------------- | Data descriptors defined here: | | index | The index (axis labels) of the Series. | | name | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __annotations__ = {'_data': <class 'pandas.core.internals.managers.Sin... | | cat = <class 'pandas.core.arrays.categorical.CategoricalAccessor'> | Accessor object for categorical properties of the Series values. | | Be aware that assigning to `categories` is a inplace operation, while all | methods return new categorical data per default (but can be called with | `inplace=True`). | | Parameters | ---------- | data : Series or CategoricalIndex | | Examples | -------- | >>> s.cat.categories | >>> s.cat.categories = list('abc') | >>> s.cat.rename_categories(list('cab')) | >>> s.cat.reorder_categories(list('cab')) | >>> s.cat.add_categories(['d','e']) | >>> s.cat.remove_categories(['d']) | >>> s.cat.remove_unused_categories() | >>> s.cat.set_categories(list('abcde')) | >>> s.cat.as_ordered() | >>> s.cat.as_unordered() | | dt = <class 'pandas.core.indexes.accessors.CombinedDatetimelikePropert... | Accessor object for datetimelike properties of the Series values. | | Examples | -------- | >>> s.dt.hour | >>> s.dt.second | >>> s.dt.quarter | | Returns a Series indexed like the original Series. | Raises TypeError if the Series does not contain datetimelike values. | | plot = <class 'pandas.plotting._core.PlotAccessor'> | Make plots of Series or DataFrame. | | Uses the backend specified by the | option ``plotting.backend``. By default, matplotlib is used. | | Parameters | ---------- | data : Series or DataFrame | The object for which the method is called. | x : label or position, default None | Only used if data is a DataFrame. | y : label, position or list of label, positions, default None | Allows plotting of one column versus another. Only used if data is a | DataFrame. | kind : str | The kind of plot to produce: | | - 'line' : line plot (default) | - 'bar' : vertical bar plot | - 'barh' : horizontal bar plot | - 'hist' : histogram | - 'box' : boxplot | - 'kde' : Kernel Density Estimation plot | - 'density' : same as 'kde' | - 'area' : area plot | - 'pie' : pie plot | - 'scatter' : scatter plot | - 'hexbin' : hexbin plot. | | figsize : a tuple (width, height) in inches | use_index : bool, default True | Use index as ticks for x axis. | title : str or list | Title to use for the plot. If a string is passed, print the string | at the top of the figure. If a list is passed and `subplots` is | True, print each item in the list above the corresponding subplot. | grid : bool, default None (matlab style default) | Axis grid lines. | legend : bool or {'reverse'} | Place legend on axis subplots. | style : list or dict | The matplotlib line style per column. | logx : bool or 'sym', default False | Use log scaling or symlog scaling on x axis. | .. versionchanged:: 0.25.0 | | logy : bool or 'sym' default False | Use log scaling or symlog scaling on y axis. | .. versionchanged:: 0.25.0 | | loglog : bool or 'sym', default False | Use log scaling or symlog scaling on both x and y axes. | .. versionchanged:: 0.25.0 | | xticks : sequence | Values to use for the xticks. | yticks : sequence | Values to use for the yticks. | xlim : 2-tuple/list | ylim : 2-tuple/list | rot : int, default None | Rotation for ticks (xticks for vertical, yticks for horizontal | plots). | fontsize : int, default None | Font size for xticks and yticks. | colormap : str or matplotlib colormap object, default None | Colormap to select colors from. If string, load colormap with that | name from matplotlib. | colorbar : bool, optional | If True, plot colorbar (only relevant for 'scatter' and 'hexbin' | plots). | position : float | Specify relative alignments for bar plot layout. | From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5 | (center). | table : bool, Series or DataFrame, default False | If True, draw a table using the data in the DataFrame and the data | will be transposed to meet matplotlib's default layout. | If a Series or DataFrame is passed, use passed data to draw a | table. | yerr : DataFrame, Series, array-like, dict and str | See :ref:`Plotting with Error Bars <visualization.errorbars>` for | detail. | xerr : DataFrame, Series, array-like, dict and str | Equivalent to yerr. | mark_right : bool, default True | When using a secondary_y axis, automatically mark the column | labels with "(right)" in the legend. | include_bool : bool, default is False | If True, boolean values can be plotted. | 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 | Options to pass to matplotlib plotting method. | | Returns | ------- | :class:`matplotlib.axes.Axes` or numpy.ndarray of them | If the backend is not the default matplotlib one, the return value | will be the object returned by the backend. | | Notes | ----- | - See matplotlib documentation online for more on this subject | - If `kind` = 'bar' or 'barh', you can specify relative alignments | for bar plot layout by `position` keyword. | From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5 | (center) | | sparse = <class 'pandas.core.arrays.sparse.accessor.SparseAccessor'> | Accessor for SparseSparse from other sparse matrix data types. | | str = <class 'pandas.core.strings.StringMethods'> | Vectorized string functions for Series and Index. NAs stay NA unless | handled otherwise by a particular method. Patterned after Python's string | methods, with some inspiration from R's stringr package. | | Examples | -------- | >>> s.str.split('_') | >>> s.str.replace('_', '') | | ---------------------------------------------------------------------- | Methods inherited from pandas.core.base.IndexOpsMixin: | | __iter__(self) | Return an iterator of the values. | | These are each a scalar type, which is a Python scalar | (for str, int, float) or a pandas scalar | (for Timestamp/Timedelta/Interval/Period) | | Returns | ------- | iterator | | argmax(self, axis=None, skipna=True, *args, **kwargs) | Return an ndarray of the maximum argument indexer. | | Parameters | ---------- | axis : {None} | Dummy argument for consistency with Series. | skipna : bool, default True | | Returns | ------- | numpy.ndarray | Indices of the maximum values. | | See Also | -------- | numpy.ndarray.argmax | | argmin(self, axis=None, skipna=True, *args, **kwargs) | Return a ndarray of the minimum argument indexer. | | Parameters | ---------- | axis : {None} | Dummy argument for consistency with Series. | skipna : bool, default True | | Returns | ------- | numpy.ndarray | | See Also | -------- | numpy.ndarray.argmin | | factorize(self, sort=False, na_sentinel=-1) | Encode the object as an enumerated type or categorical variable. | | This method is useful for obtaining a numeric representation of an | array when all that matters is identifying distinct values. `factorize` | is available as both a top-level function :func:`pandas.factorize`, | and as a method :meth:`Series.factorize` and :meth:`Index.factorize`. | | Parameters | ---------- | sort : bool, default False | Sort `uniques` and shuffle `codes` to maintain the | relationship. | | na_sentinel : int, default -1 | Value to mark "not found". | | Returns | ------- | codes : ndarray | An integer ndarray that's an indexer into `uniques`. | ``uniques.take(codes)`` will have the same values as `values`. | uniques : ndarray, Index, or Categorical | The unique valid values. When `values` is Categorical, `uniques` | is a Categorical. When `values` is some other pandas object, an | `Index` is returned. Otherwise, a 1-D ndarray is returned. | | .. note :: | | Even if there's a missing value in `values`, `uniques` will | *not* contain an entry for it. | | See Also | -------- | cut : Discretize continuous-valued array. | unique : Find the unique value in an array. | | Examples | -------- | These examples all show factorize as a top-level method like | ``pd.factorize(values)``. The results are identical for methods like | :meth:`Series.factorize`. | | >>> codes, uniques = pd.factorize(['b', 'b', 'a', 'c', 'b']) | >>> codes | array([0, 0, 1, 2, 0]) | >>> uniques | array(['b', 'a', 'c'], dtype=object) | | With ``sort=True``, the `uniques` will be sorted, and `codes` will be | shuffled so that the relationship is the maintained. | | >>> codes, uniques = pd.factorize(['b', 'b', 'a', 'c', 'b'], sort=True) | >>> codes | array([1, 1, 0, 2, 1]) | >>> uniques | array(['a', 'b', 'c'], dtype=object) | | Missing values are indicated in `codes` with `na_sentinel` | (``-1`` by default). Note that missing values are never | included in `uniques`. | | >>> codes, uniques = pd.factorize(['b', None, 'a', 'c', 'b']) | >>> codes | array([ 0, -1, 1, 2, 0]) | >>> uniques | array(['b', 'a', 'c'], dtype=object) | | Thus far, we've only factorized lists (which are internally coerced to | NumPy arrays). When factorizing pandas objects, the type of `uniques` | will differ. For Categoricals, a `Categorical` is returned. | | >>> cat = pd.Categorical(['a', 'a', 'c'], categories=['a', 'b', 'c']) | >>> codes, uniques = pd.factorize(cat) | >>> codes | array([0, 0, 1]) | >>> uniques | [a, c] | Categories (3, object): [a, b, c] | | Notice that ``'b'`` is in ``uniques.categories``, despite not being | present in ``cat.values``. | | For all other pandas objects, an Index of the appropriate type is | returned. | | >>> cat = pd.Series(['a', 'a', 'c']) | >>> codes, uniques = pd.factorize(cat) | >>> codes | array([0, 0, 1]) | >>> uniques | Index(['a', 'c'], dtype='object') | | item(self) | Return the first element of the underlying data as a python scalar. | | Returns | ------- | scalar | The first element of %(klass)s. | | Raises | ------ | ValueError | If the data is not length-1. | | nunique(self, dropna=True) | Return number of unique elements in the object. | | Excludes NA values by default. | | Parameters | ---------- | dropna : bool, default True | Don't include NaN in the count. | | Returns | ------- | int | | See Also | -------- | DataFrame.nunique: Method nunique for DataFrame. | Series.count: Count non-NA/null observations in the Series. | | Examples | -------- | >>> s = pd.Series([1, 3, 5, 7, 7]) | >>> s | 0 1 | 1 3 | 2 5 | 3 7 | 4 7 | dtype: int64 | | >>> s.nunique() | 4 | | to_list = tolist(self) | | to_numpy(self, dtype=None, copy=False, na_value=<object object at 0x7fed2359e980>, **kwargs) | A NumPy ndarray representing the values in this Series or Index. | | .. versionadded:: 0.24.0 | | Parameters | ---------- | dtype : str or numpy.dtype, optional | The dtype to pass to :meth:`numpy.asarray`. | copy : bool, default False | Whether to ensure that the returned value is a not a view on | another array. Note that ``copy=False`` does not *ensure* that | ``to_numpy()`` is no-copy. Rather, ``copy=True`` ensure that | a copy is made, even if not strictly necessary. | na_value : Any, optional | The value to use for missing values. The default value depends | on `dtype` and the type of the array. | | .. versionadded:: 1.0.0 | | **kwargs | Additional keywords passed through to the ``to_numpy`` method | of the underlying array (for extension arrays). | | .. versionadded:: 1.0.0 | | Returns | ------- | numpy.ndarray | | See Also | -------- | Series.array : Get the actual data stored within. | Index.array : Get the actual data stored within. | DataFrame.to_numpy : Similar method for DataFrame. | | Notes | ----- | The returned array will be the same up to equality (values equal | in `self` will be equal in the returned array; likewise for values | that are not equal). When `self` contains an ExtensionArray, the | dtype may be different. For example, for a category-dtype Series, | ``to_numpy()`` will return a NumPy array and the categorical dtype | will be lost. | | For NumPy dtypes, this will be a reference to the actual data stored | in this Series or Index (assuming ``copy=False``). Modifying the result | in place will modify the data stored in the Series or Index (not that | we recommend doing that). | | For extension types, ``to_numpy()`` *may* require copying data and | coercing the result to a NumPy type (possibly object), which may be | expensive. When you need a no-copy reference to the underlying data, | :attr:`Series.array` should be used instead. | | This table lays out the different dtypes and default return types of | ``to_numpy()`` for various dtypes within pandas. | | ================== ================================ | dtype array type | ================== ================================ | category[T] ndarray[T] (same dtype as input) | period ndarray[object] (Periods) | interval ndarray[object] (Intervals) | IntegerNA ndarray[object] | datetime64[ns] datetime64[ns] | datetime64[ns, tz] ndarray[object] (Timestamps) | ================== ================================ | | Examples | -------- | >>> ser = pd.Series(pd.Categorical(['a', 'b', 'a'])) | >>> ser.to_numpy() | array(['a', 'b', 'a'], dtype=object) | | Specify the `dtype` to control how datetime-aware data is represented. | Use ``dtype=object`` to return an ndarray of pandas :class:`Timestamp` | objects, each with the correct ``tz``. | | >>> ser = pd.Series(pd.date_range('2000', periods=2, tz="CET")) | >>> ser.to_numpy(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 ``dtype='datetime64[ns]'`` to return an ndarray of native | datetime64 values. The values are converted to UTC and the timezone | info is dropped. | | >>> ser.to_numpy(dtype="datetime64[ns]") | ... # doctest: +ELLIPSIS | array(['1999-12-31T23:00:00.000000000', '2000-01-01T23:00:00...'], | dtype='datetime64[ns]') | | tolist(self) | Return a list of the values. | | These are each a scalar type, which is a Python scalar | (for str, int, float) or a pandas scalar | (for Timestamp/Timedelta/Interval/Period) | | Returns | ------- | list | | See Also | -------- | numpy.ndarray.tolist | | transpose(self, *args, **kwargs) | Return the transpose, which is by definition self. | | Returns | ------- | %(klass)s | | value_counts(self, normalize=False, sort=True, ascending=False, bins=None, dropna=True) | Return a Series containing counts of unique values. | | The resulting object will be in descending order so that the | first element is the most frequently-occurring element. | Excludes NA values by default. | | Parameters | ---------- | normalize : bool, default False | If True then the object returned will contain the relative | frequencies of the unique values. | sort : bool, default True | Sort by frequencies. | ascending : bool, default False | Sort in ascending order. | bins : int, optional | Rather than count values, group them into half-open bins, | a convenience for ``pd.cut``, only works with numeric data. | dropna : bool, default True | Don't include counts of NaN. | | Returns | ------- | Series | | See Also | -------- | Series.count: Number of non-NA elements in a Series. | DataFrame.count: Number of non-NA elements in a DataFrame. | | Examples | -------- | >>> index = pd.Index([3, 1, 2, 3, 4, np.nan]) | >>> index.value_counts() | 3.0 2 | 4.0 1 | 2.0 1 | 1.0 1 | dtype: int64 | | With `normalize` set to `True`, returns the relative frequency by | dividing all values by the sum of values. | | >>> s = pd.Series([3, 1, 2, 3, 4, np.nan]) | >>> s.value_counts(normalize=True) | 3.0 0.4 | 4.0 0.2 | 2.0 0.2 | 1.0 0.2 | dtype: float64 | | **bins** | | Bins can be useful for going from a continuous variable to a | categorical variable; instead of counting unique | apparitions of values, divide the index in the specified | number of half-open bins. | | >>> s.value_counts(bins=3) | (2.0, 3.0] 2 | (0.996, 2.0] 2 | (3.0, 4.0] 1 | dtype: int64 | | **dropna** | | With `dropna` set to `False` we can also see NaN index values. | | >>> s.value_counts(dropna=False) | 3.0 2 | NaN 1 | 4.0 1 | 2.0 1 | 1.0 1 | dtype: int64 | | ---------------------------------------------------------------------- | Readonly properties inherited from pandas.core.base.IndexOpsMixin: | | T | Return the transpose, which is by definition self. | | empty | | is_monotonic | Return boolean if values in the object are | monotonic_increasing. | | Returns | ------- | bool | | is_monotonic_decreasing | Return boolean if values in the object are | monotonic_decreasing. | | Returns | ------- | bool | | is_monotonic_increasing | Return boolean if values in the object are | monotonic_increasing. | | Returns | ------- | bool | | is_unique | Return boolean if values in the object are unique. | | Returns | ------- | bool | | nbytes | Return the number of bytes in the underlying data. | | ndim | Number of dimensions of the underlying data, by definition 1. | | shape | Return a tuple of the shape of the underlying data. | | size | Return the number of elements in the underlying data. | | ---------------------------------------------------------------------- | Data descriptors inherited from pandas.core.base.IndexOpsMixin: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Data and other attributes inherited from pandas.core.base.IndexOpsMixin: | | __array_priority__ = 1000 | | ---------------------------------------------------------------------- | Methods inherited from pandas.core.generic.NDFrame: | | __abs__(self: ~FrameOrSeries) -> ~FrameOrSeries | | __array_wrap__(self, result, context=None) | | __bool__ = __nonzero__(self) | | __contains__(self, key) -> bool | True if the key is in the info axis | | __copy__(self: ~FrameOrSeries, deep: bool = True) -> ~FrameOrSeries | | __deepcopy__(self: ~FrameOrSeries, memo=None) -> ~FrameOrSeries | Parameters | ---------- | memo, default None | Standard signature. Unused | | __delitem__(self, key) -> None | Delete item | | __finalize__(self: ~FrameOrSeries, other, method=None, **kwargs) -> ~FrameOrSeries | Propagate metadata from other to self. | | Parameters | ---------- | other : the object from which to get the attributes that we are going | to propagate | method : optional, a passed method name ; possibly to take different | types of propagation actions based on this | | __getattr__(self, name: str) | After regular attribute access, try looking up the name | This allows simpler access to columns for interactive use. | | __getstate__(self) -> Dict[str, Any] | | __hash__(self) | Return hash(self). | | __invert__(self) | | __neg__(self) | | __nonzero__(self) | | __pos__(self) | | __round__(self: ~FrameOrSeries, decimals: int = 0) -> ~FrameOrSeries | | __setattr__(self, name: str, value) -> None | After regular attribute access, try setting the name | This allows simpler access to columns for interactive use. | | __setstate__(self, state) | | abs(self: ~FrameOrSeries) -> ~FrameOrSeries | Return a Series/DataFrame with absolute numeric value of each element. | | This function only applies to elements that are all numeric. | | Returns | ------- | abs | Series/DataFrame containing the absolute value of each element. | | See Also | -------- | numpy.absolute : Calculate the absolute value element-wise. | | Notes | ----- | For ``complex`` inputs, ``1.2 + 1j``, the absolute value is | :math:`\sqrt{ a^2 + b^2 }`. | | Examples | -------- | Absolute numeric values in a Series. | | >>> s = pd.Series([-1.10, 2, -3.33, 4]) | >>> s.abs() | 0 1.10 | 1 2.00 | 2 3.33 | 3 4.00 | dtype: float64 | | Absolute numeric values in a Series with complex numbers. | | >>> s = pd.Series([1.2 + 1j]) | >>> s.abs() | 0 1.56205 | dtype: float64 | | Absolute numeric values in a Series with a Timedelta element. | | >>> s = pd.Series([pd.Timedelta('1 days')]) | >>> s.abs() | 0 1 days | dtype: timedelta64[ns] | | Select rows with data closest to certain value using argsort (from | `StackOverflow <https://stackoverflow.com/a/17758115>`__). | | >>> df = pd.DataFrame({ | ... 'a': [4, 5, 6, 7], | ... 'b': [10, 20, 30, 40], | ... 'c': [100, 50, -30, -50] | ... }) | >>> df | a b c | 0 4 10 100 | 1 5 20 50 | 2 6 30 -30 | 3 7 40 -50 | >>> df.loc[(df.c - 43).abs().argsort()] | a b c | 1 5 20 50 | 0 4 10 100 | 2 6 30 -30 | 3 7 40 -50 | | add_prefix(self: ~FrameOrSeries, prefix: str) -> ~FrameOrSeries | Prefix labels with string `prefix`. | | For Series, the row labels are prefixed. | For DataFrame, the column labels are prefixed. | | Parameters | ---------- | prefix : str | The string to add before each label. | | Returns | ------- | Series or DataFrame | New Series or DataFrame with updated labels. | | See Also | -------- | Series.add_suffix: Suffix row labels with string `suffix`. | DataFrame.add_suffix: Suffix column labels with string `suffix`. | | Examples | -------- | >>> s = pd.Series([1, 2, 3, 4]) | >>> s | 0 1 | 1 2 | 2 3 | 3 4 | dtype: int64 | | >>> s.add_prefix('item_') | item_0 1 | item_1 2 | item_2 3 | item_3 4 | dtype: int64 | | >>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]}) | >>> df | A B | 0 1 3 | 1 2 4 | 2 3 5 | 3 4 6 | | >>> df.add_prefix('col_') | col_A col_B | 0 1 3 | 1 2 4 | 2 3 5 | 3 4 6 | | add_suffix(self: ~FrameOrSeries, suffix: str) -> ~FrameOrSeries | Suffix labels with string `suffix`. | | For Series, the row labels are suffixed. | For DataFrame, the column labels are suffixed. | | Parameters | ---------- | suffix : str | The string to add after each label. | | Returns | ------- | Series or DataFrame | New Series or DataFrame with updated labels. | | See Also | -------- | Series.add_prefix: Prefix row labels with string `prefix`. | DataFrame.add_prefix: Prefix column labels with string `prefix`. | | Examples | -------- | >>> s = pd.Series([1, 2, 3, 4]) | >>> s | 0 1 | 1 2 | 2 3 | 3 4 | dtype: int64 | | >>> s.add_suffix('_item') | 0_item 1 | 1_item 2 | 2_item 3 | 3_item 4 | dtype: int64 | | >>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]}) | >>> df | A B | 0 1 3 | 1 2 4 | 2 3 5 | 3 4 6 | | >>> df.add_suffix('_col') | A_col B_col | 0 1 3 | 1 2 4 | 2 3 5 | 3 4 6 | | asfreq(self: ~FrameOrSeries, freq, method=None, how: Union[str, NoneType] = None, normalize: bool = False, fill_value=None) -> ~FrameOrSeries | Convert TimeSeries to specified frequency. | | Optionally provide filling method to pad/backfill missing values. | | Returns the original data conformed to a new index with the specified | frequency. ``resample`` is more appropriate if an operation, such as | summarization, is necessary to represent the data at the new frequency. | | Parameters | ---------- | freq : DateOffset or str | method : {'backfill'/'bfill', 'pad'/'ffill'}, default None | Method to use for filling holes in reindexed Series (note this | does not fill NaNs that already were present): | | * 'pad' / 'ffill': propagate last valid observation forward to next | valid | * 'backfill' / 'bfill': use NEXT valid observation to fill. | how : {'start', 'end'}, default end | For PeriodIndex only (see PeriodIndex.asfreq). | normalize : bool, default False | Whether to reset output index to midnight. | fill_value : scalar, optional | Value to use for missing values, applied during upsampling (note | this does not fill NaNs that already were present). | | Returns | ------- | converted : same type as caller | | See Also | -------- | reindex | | Notes | ----- | To learn more about the frequency strings, please see `this link | <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__. | | Examples | -------- | | Start by creating a series with 4 one minute timestamps. | | >>> index = pd.date_range('1/1/2000', periods=4, freq='T') | >>> series = pd.Series([0.0, None, 2.0, 3.0], index=index) | >>> df = pd.DataFrame({'s':series}) | >>> df | s | 2000-01-01 00:00:00 0.0 | 2000-01-01 00:01:00 NaN | 2000-01-01 00:02:00 2.0 | 2000-01-01 00:03:00 3.0 | | Upsample the series into 30 second bins. | | >>> df.asfreq(freq='30S') | s | 2000-01-01 00:00:00 0.0 | 2000-01-01 00:00:30 NaN | 2000-01-01 00:01:00 NaN | 2000-01-01 00:01:30 NaN | 2000-01-01 00:02:00 2.0 | 2000-01-01 00:02:30 NaN | 2000-01-01 00:03:00 3.0 | | Upsample again, providing a ``fill value``. | | >>> df.asfreq(freq='30S', fill_value=9.0) | s | 2000-01-01 00:00:00 0.0 | 2000-01-01 00:00:30 9.0 | 2000-01-01 00:01:00 NaN | 2000-01-01 00:01:30 9.0 | 2000-01-01 00:02:00 2.0 | 2000-01-01 00:02:30 9.0 | 2000-01-01 00:03:00 3.0 | | Upsample again, providing a ``method``. | | >>> df.asfreq(freq='30S', method='bfill') | s | 2000-01-01 00:00:00 0.0 | 2000-01-01 00:00:30 NaN | 2000-01-01 00:01:00 NaN | 2000-01-01 00:01:30 2.0 | 2000-01-01 00:02:00 2.0 | 2000-01-01 00:02:30 3.0 | 2000-01-01 00:03:00 3.0 | | asof(self, where, subset=None) | Return the last row(s) without any NaNs before `where`. | | The last row (for each element in `where`, if list) without any | NaN is taken. | In case of a :class:`~pandas.DataFrame`, the last row without NaN | considering only the subset of columns (if not `None`) | | If there is no good value, NaN is returned for a Series or | a Series of NaN values for a DataFrame | | Parameters | ---------- | where : date or array-like of dates | Date(s) before which the last row(s) are returned. | subset : str or array-like of str, default `None` | For DataFrame, if not `None`, only use these columns to | check for NaNs. | | Returns | ------- | scalar, Series, or DataFrame | | The return can be: | | * scalar : when `self` is a Series and `where` is a scalar | * Series: when `self` is a Series and `where` is an array-like, | or when `self` is a DataFrame and `where` is a scalar | * DataFrame : when `self` is a DataFrame and `where` is an | array-like | | Return scalar, Series, or DataFrame. | | See Also | -------- | merge_asof : Perform an asof merge. Similar to left join. | | Notes | ----- | Dates are assumed to be sorted. Raises if this is not the case. | | Examples | -------- | A Series and a scalar `where`. | | >>> s = pd.Series([1, 2, np.nan, 4], index=[10, 20, 30, 40]) | >>> s | 10 1.0 | 20 2.0 | 30 NaN | 40 4.0 | dtype: float64 | | >>> s.asof(20) | 2.0 | | For a sequence `where`, a Series is returned. The first value is | NaN, because the first element of `where` is before the first | index value. | | >>> s.asof([5, 20]) | 5 NaN | 20 2.0 | dtype: float64 | | Missing values are not considered. The following is ``2.0``, not | NaN, even though NaN is at the index location for ``30``. | | >>> s.asof(30) | 2.0 | | Take all columns into consideration | | >>> df = pd.DataFrame({'a': [10, 20, 30, 40, 50], | ... 'b': [None, None, None, None, 500]}, | ... index=pd.DatetimeIndex(['2018-02-27 09:01:00', | ... '2018-02-27 09:02:00', | ... '2018-02-27 09:03:00', | ... '2018-02-27 09:04:00', | ... '2018-02-27 09:05:00'])) | >>> df.asof(pd.DatetimeIndex(['2018-02-27 09:03:30', | ... '2018-02-27 09:04:30'])) | a b | 2018-02-27 09:03:30 NaN NaN | 2018-02-27 09:04:30 NaN NaN | | Take a single column into consideration | | >>> df.asof(pd.DatetimeIndex(['2018-02-27 09:03:30', | ... '2018-02-27 09:04:30']), | ... subset=['a']) | a b | 2018-02-27 09:03:30 30.0 NaN | 2018-02-27 09:04:30 40.0 NaN | | astype(self: ~FrameOrSeries, dtype, copy: bool = True, errors: str = 'raise') -> ~FrameOrSeries | Cast a pandas object to a specified dtype ``dtype``. | | Parameters | ---------- | dtype : data type, or dict of column name -> data type | Use a numpy.dtype or Python type to cast entire pandas object to | the same type. Alternatively, use {col: dtype, ...}, where col is a | column label and dtype is a numpy.dtype or Python type to cast one | or more of the DataFrame's columns to column-specific types. | copy : bool, default True | Return a copy when ``copy=True`` (be very careful setting | ``copy=False`` as changes to values then may propagate to other | pandas objects). | errors : {'raise', 'ignore'}, default 'raise' | Control raising of exceptions on invalid data for provided dtype. | | - ``raise`` : allow exceptions to be raised | - ``ignore`` : suppress exceptions. On error return original object. | | Returns | ------- | casted : same type as caller | | See Also | -------- | to_datetime : Convert argument to datetime. | to_timedelta : Convert argument to timedelta. | to_numeric : Convert argument to a numeric type. | numpy.ndarray.astype : Cast a numpy array to a specified type. | | Examples | -------- | Create a DataFrame: | | >>> d = {'col1': [1, 2], 'col2': [3, 4]} | >>> df = pd.DataFrame(data=d) | >>> df.dtypes | col1 int64 | col2 int64 | dtype: object | | Cast all columns to int32: | | >>> df.astype('int32').dtypes | col1 int32 | col2 int32 | dtype: object | | Cast col1 to int32 using a dictionary: | | >>> df.astype({'col1': 'int32'}).dtypes | col1 int32 | col2 int64 | dtype: object | | Create a series: | | >>> ser = pd.Series([1, 2], dtype='int32') | >>> ser | 0 1 | 1 2 | dtype: int32 | >>> ser.astype('int64') | 0 1 | 1 2 | dtype: int64 | | Convert to categorical type: | | >>> ser.astype('category') | 0 1 | 1 2 | dtype: category | Categories (2, int64): [1, 2] | | Convert to ordered categorical type with custom ordering: | | >>> cat_dtype = pd.api.types.CategoricalDtype( | ... categories=[2, 1], ordered=True) | >>> ser.astype(cat_dtype) | 0 1 | 1 2 | dtype: category | Categories (2, int64): [2 < 1] | | Note that using ``copy=False`` and changing data on a new | pandas object may propagate changes: | | >>> s1 = pd.Series([1, 2]) | >>> s2 = s1.astype('int64', copy=False) | >>> s2[0] = 10 | >>> s1 # note that s1[0] has changed too | 0 10 | 1 2 | dtype: int64 | | at_time(self: ~FrameOrSeries, time, asof: bool = False, axis=None) -> ~FrameOrSeries | Select values at particular time of day (e.g. 9:30AM). | | Parameters | ---------- | time : datetime.time or str | axis : {0 or 'index', 1 or 'columns'}, default 0 | | .. versionadded:: 0.24.0 | | Returns | ------- | Series or DataFrame | | Raises | ------ | TypeError | If the index is not a :class:`DatetimeIndex` | | See Also | -------- | between_time : Select values between particular times of the day. | first : Select initial periods of time series based on a date offset. | last : Select final periods of time series based on a date offset. | DatetimeIndex.indexer_at_time : Get just the index locations for | values at particular time of the day. | | Examples | -------- | >>> i = pd.date_range('2018-04-09', periods=4, freq='12H') | >>> ts = pd.DataFrame({'A': [1, 2, 3, 4]}, index=i) | >>> ts | A | 2018-04-09 00:00:00 1 | 2018-04-09 12:00:00 2 | 2018-04-10 00:00:00 3 | 2018-04-10 12:00:00 4 | | >>> ts.at_time('12:00') | A | 2018-04-09 12:00:00 2 | 2018-04-10 12:00:00 4 | | between_time(self: ~FrameOrSeries, start_time, end_time, include_start: bool = True, include_end: bool = True, axis=None) -> ~FrameOrSeries | Select values between particular times of the day (e.g., 9:00-9:30 AM). | | By setting ``start_time`` to be later than ``end_time``, | you can get the times that are *not* between the two times. | | Parameters | ---------- | start_time : datetime.time or str | end_time : datetime.time or str | include_start : bool, default True | include_end : bool, default True | axis : {0 or 'index', 1 or 'columns'}, default 0 | | .. versionadded:: 0.24.0 | | Returns | ------- | Series or DataFrame | | Raises | ------ | TypeError | If the index is not a :class:`DatetimeIndex` | | See Also | -------- | at_time : Select values at a particular time of the day. | first : Select initial periods of time series based on a date offset. | last : Select final periods of time series based on a date offset. | DatetimeIndex.indexer_between_time : Get just the index locations for | values between particular times of the day. | | Examples | -------- | >>> i = pd.date_range('2018-04-09', periods=4, freq='1D20min') | >>> ts = pd.DataFrame({'A': [1, 2, 3, 4]}, index=i) | >>> ts | A | 2018-04-09 00:00:00 1 | 2018-04-10 00:20:00 2 | 2018-04-11 00:40:00 3 | 2018-04-12 01:00:00 4 | | >>> ts.between_time('0:15', '0:45') | A | 2018-04-10 00:20:00 2 | 2018-04-11 00:40:00 3 | | You get the times that are *not* between two times by setting | ``start_time`` later than ``end_time``: | | >>> ts.between_time('0:45', '0:15') | A | 2018-04-09 00:00:00 1 | 2018-04-12 01:00:00 4 | | bfill(self: ~FrameOrSeries, axis=None, inplace: bool = False, limit=None, downcast=None) -> Union[~FrameOrSeries, NoneType] | Synonym for :meth:`DataFrame.fillna` with ``method='bfill'``. | | Returns | ------- | %(klass)s or None | Object with missing values filled or None if ``inplace=True``. | | bool(self) | Return the bool of a single element PandasObject. | | This must be a boolean scalar value, either True or False. Raise a | ValueError if the PandasObject does not have exactly 1 element, or that | element is not boolean | | Returns | ------- | bool | Same single boolean value converted to bool type. | | clip(self: ~FrameOrSeries, lower=None, upper=None, axis=None, inplace: bool = False, *args, **kwargs) -> ~FrameOrSeries | Trim values at input threshold(s). | | Assigns values outside boundary to boundary values. Thresholds | can be singular values or array like, and in the latter case | the clipping is performed element-wise in the specified axis. | | Parameters | ---------- | lower : float or array_like, default None | Minimum threshold value. All values below this | threshold will be set to it. | upper : float or array_like, default None | Maximum threshold value. All values above this | threshold will be set to it. | axis : int or str axis name, optional | Align object with lower and upper along the given axis. | inplace : bool, default False | Whether to perform the operation in place on the data. | | .. versionadded:: 0.21.0 | *args, **kwargs | Additional keywords have no effect but might be accepted | for compatibility with numpy. | | Returns | ------- | Series or DataFrame | Same type as calling object with the values outside the | clip boundaries replaced. | | Examples | -------- | >>> data = {'col_0': [9, -3, 0, -1, 5], 'col_1': [-2, -7, 6, 8, -5]} | >>> df = pd.DataFrame(data) | >>> df | col_0 col_1 | 0 9 -2 | 1 -3 -7 | 2 0 6 | 3 -1 8 | 4 5 -5 | | Clips per column using lower and upper thresholds: | | >>> df.clip(-4, 6) | col_0 col_1 | 0 6 -2 | 1 -3 -4 | 2 0 6 | 3 -1 6 | 4 5 -4 | | Clips using specific lower and upper thresholds per column element: | | >>> t = pd.Series([2, -4, -1, 6, 3]) | >>> t | 0 2 | 1 -4 | 2 -1 | 3 6 | 4 3 | dtype: int64 | | >>> df.clip(t, t + 4, axis=0) | col_0 col_1 | 0 6 2 | 1 -3 -4 | 2 0 3 | 3 6 8 | 4 5 3 | | convert_dtypes(self: ~FrameOrSeries, infer_objects: bool = True, convert_string: bool = True, convert_integer: bool = True, convert_boolean: bool = True) -> ~FrameOrSeries | Convert columns to best possible dtypes using dtypes supporting ``pd.NA``. | | .. versionadded:: 1.0.0 | | Parameters | ---------- | infer_objects : bool, default True | Whether object dtypes should be converted to the best possible types. | convert_string : bool, default True | Whether object dtypes should be converted to ``StringDtype()``. | convert_integer : bool, default True | Whether, if possible, conversion can be done to integer extension types. | convert_boolean : bool, defaults True | Whether object dtypes should be converted to ``BooleanDtypes()``. | | Returns | ------- | Series or DataFrame | Copy of input object with new dtype. | | See Also | -------- | infer_objects : Infer dtypes of objects. | to_datetime : Convert argument to datetime. | to_timedelta : Convert argument to timedelta. | to_numeric : Convert argument to a numeric type. | | Notes | ----- | | By default, ``convert_dtypes`` will attempt to convert a Series (or each | Series in a DataFrame) to dtypes that support ``pd.NA``. By using the options | ``convert_string``, ``convert_integer``, and ``convert_boolean``, it is | possible to turn off individual conversions to ``StringDtype``, the integer | extension types or ``BooleanDtype``, respectively. | | For object-dtyped columns, if ``infer_objects`` is ``True``, use the inference | rules as during normal Series/DataFrame construction. Then, if possible, | convert to ``StringDtype``, ``BooleanDtype`` or an appropriate integer extension | type, otherwise leave as ``object``. | | If the dtype is integer, convert to an appropriate integer extension type. | | If the dtype is numeric, and consists of all integers, convert to an | appropriate integer extension type. | | In the future, as new dtypes are added that support ``pd.NA``, the results | of this method will change to support those new dtypes. | | Examples | -------- | >>> df = pd.DataFrame( | ... { | ... "a": pd.Series([1, 2, 3], dtype=np.dtype("int32")), | ... "b": pd.Series(["x", "y", "z"], dtype=np.dtype("O")), | ... "c": pd.Series([True, False, np.nan], dtype=np.dtype("O")), | ... "d": pd.Series(["h", "i", np.nan], dtype=np.dtype("O")), | ... "e": pd.Series([10, np.nan, 20], dtype=np.dtype("float")), | ... "f": pd.Series([np.nan, 100.5, 200], dtype=np.dtype("float")), | ... } | ... ) | | Start with a DataFrame with default dtypes. | | >>> df | a b c d e f | 0 1 x True h 10.0 NaN | 1 2 y False i NaN 100.5 | 2 3 z NaN NaN 20.0 200.0 | | >>> df.dtypes | a int32 | b object | c object | d object | e float64 | f float64 | dtype: object | | Convert the DataFrame to use best possible dtypes. | | >>> dfn = df.convert_dtypes() | >>> dfn | a b c d e f | 0 1 x True h 10 NaN | 1 2 y False i <NA> 100.5 | 2 3 z <NA> <NA> 20 200.0 | | >>> dfn.dtypes | a Int32 | b string | c boolean | d string | e Int64 | f float64 | dtype: object | | Start with a Series of strings and missing data represented by ``np.nan``. | | >>> s = pd.Series(["a", "b", np.nan]) | >>> s | 0 a | 1 b | 2 NaN | dtype: object | | Obtain a Series with dtype ``StringDtype``. | | >>> s.convert_dtypes() | 0 a | 1 b | 2 <NA> | dtype: string | | copy(self: ~FrameOrSeries, deep: bool = True) -> ~FrameOrSeries | Make a copy of this object's indices and data. | | When ``deep=True`` (default), a new object will be created with a | copy of the calling object's data and indices. Modifications to | the data or indices of the copy will not be reflected in the | original object (see notes below). | | When ``deep=False``, a new object will be created without copying | the calling object's data or index (only references to the data | and index are copied). Any changes to the data of the original | will be reflected in the shallow copy (and vice versa). | | Parameters | ---------- | deep : bool, default True | Make a deep copy, including a copy of the data and the indices. | With ``deep=False`` neither the indices nor the data are copied. | | Returns | ------- | copy : Series or DataFrame | Object type matches caller. | | Notes | ----- | When ``deep=True``, data is copied but actual Python objects | will not be copied recursively, only the reference to the object. | This is in contrast to `copy.deepcopy` in the Standard Library, | which recursively copies object data (see examples below). | | While ``Index`` objects are copied when ``deep=True``, the underlying | numpy array is not copied for performance reasons. Since ``Index`` is | immutable, the underlying data can be safely shared and a copy | is not needed. | | Examples | -------- | >>> s = pd.Series([1, 2], index=["a", "b"]) | >>> s | a 1 | b 2 | dtype: int64 | | >>> s_copy = s.copy() | >>> s_copy | a 1 | b 2 | dtype: int64 | | **Shallow copy versus default (deep) copy:** | | >>> s = pd.Series([1, 2], index=["a", "b"]) | >>> deep = s.copy() | >>> shallow = s.copy(deep=False) | | Shallow copy shares data and index with original. | | >>> s is shallow | False | >>> s.values is shallow.values and s.index is shallow.index | True | | Deep copy has own copy of data and index. | | >>> s is deep | False | >>> s.values is deep.values or s.index is deep.index | False | | Updates to the data shared by shallow copy and original is reflected | in both; deep copy remains unchanged. | | >>> s[0] = 3 | >>> shallow[1] = 4 | >>> s | a 3 | b 4 | dtype: int64 | >>> shallow | a 3 | b 4 | dtype: int64 | >>> deep | a 1 | b 2 | dtype: int64 | | Note that when copying an object containing Python objects, a deep copy | will copy the data, but will not do so recursively. Updating a nested | data object will be reflected in the deep copy. | | >>> s = pd.Series([[1, 2], [3, 4]]) | >>> deep = s.copy() | >>> s[0][0] = 10 | >>> s | 0 [10, 2] | 1 [3, 4] | dtype: object | >>> deep | 0 [10, 2] | 1 [3, 4] | dtype: object | | describe(self: ~FrameOrSeries, percentiles=None, include=None, exclude=None) -> ~FrameOrSeries | Generate descriptive statistics. | | Descriptive statistics include those that summarize the central | tendency, dispersion and shape of a | dataset's distribution, excluding ``NaN`` values. | | Analyzes both numeric and object series, as well | as ``DataFrame`` column sets of mixed data types. The output | will vary depending on what is provided. Refer to the notes | below for more detail. | | Parameters | ---------- | percentiles : list-like of numbers, optional | The percentiles to include in the output. All should | fall between 0 and 1. The default is | ``[.25, .5, .75]``, which returns the 25th, 50th, and | 75th percentiles. | include : 'all', list-like of dtypes or None (default), optional | A white list of data types to include in the result. Ignored | for ``Series``. Here are the options: | | - 'all' : All columns of the input will be included in the output. | - A list-like of dtypes : Limits the results to the | provided data types. | To limit the result to numeric types submit | ``numpy.number``. To limit it instead to object columns submit | the ``numpy.object`` data type. Strings | can also be used in the style of | ``select_dtypes`` (e.g. ``df.describe(include=['O'])``). To | select pandas categorical columns, use ``'category'`` | - None (default) : The result will include all numeric columns. | exclude : list-like of dtypes or None (default), optional, | A black list of data types to omit from the result. Ignored | for ``Series``. Here are the options: | | - A list-like of dtypes : Excludes the provided data types | from the result. To exclude numeric types submit | ``numpy.number``. To exclude object columns submit the data | type ``numpy.object``. Strings can also be used in the style of | ``select_dtypes`` (e.g. ``df.describe(include=['O'])``). To | exclude pandas categorical columns, use ``'category'`` | - None (default) : The result will exclude nothing. | | Returns | ------- | Series or DataFrame | Summary statistics of the Series or Dataframe provided. | | See Also | -------- | DataFrame.count: Count number of non-NA/null observations. | DataFrame.max: Maximum of the values in the object. | DataFrame.min: Minimum of the values in the object. | DataFrame.mean: Mean of the values. | DataFrame.std: Standard deviation of the observations. | DataFrame.select_dtypes: Subset of a DataFrame including/excluding | columns based on their dtype. | | Notes | ----- | For numeric data, the result's index will include ``count``, | ``mean``, ``std``, ``min``, ``max`` as well as lower, ``50`` and | upper percentiles. By default the lower percentile is ``25`` and the | upper percentile is ``75``. The ``50`` percentile is the | same as the median. | | For object data (e.g. strings or timestamps), the result's index | will include ``count``, ``unique``, ``top``, and ``freq``. The ``top`` | is the most common value. The ``freq`` is the most common value's | frequency. Timestamps also include the ``first`` and ``last`` items. | | If multiple object values have the highest count, then the | ``count`` and ``top`` results will be arbitrarily chosen from | among those with the highest count. | | For mixed data types provided via a ``DataFrame``, the default is to | return only an analysis of numeric columns. If the dataframe consists | only of object and categorical data without any numeric columns, the | default is to return an analysis of both the object and categorical | columns. If ``include='all'`` is provided as an option, the result | will include a union of attributes of each type. | | The `include` and `exclude` parameters can be used to limit | which columns in a ``DataFrame`` are analyzed for the output. | The parameters are ignored when analyzing a ``Series``. | | Examples | -------- | Describing a numeric ``Series``. | | >>> s = pd.Series([1, 2, 3]) | >>> s.describe() | count 3.0 | mean 2.0 | std 1.0 | min 1.0 | 25% 1.5 | 50% 2.0 | 75% 2.5 | max 3.0 | dtype: float64 | | Describing a categorical ``Series``. | | >>> s = pd.Series(['a', 'a', 'b', 'c']) | >>> s.describe() | count 4 | unique 3 | top a | freq 2 | dtype: object | | Describing a timestamp ``Series``. | | >>> s = pd.Series([ | ... np.datetime64("2000-01-01"), | ... np.datetime64("2010-01-01"), | ... np.datetime64("2010-01-01") | ... ]) | >>> s.describe() | count 3 | unique 2 | top 2010-01-01 00:00:00 | freq 2 | first 2000-01-01 00:00:00 | last 2010-01-01 00:00:00 | dtype: object | | Describing a ``DataFrame``. By default only numeric fields | are returned. | | >>> df = pd.DataFrame({'categorical': pd.Categorical(['d','e','f']), | ... 'numeric': [1, 2, 3], | ... 'object': ['a', 'b', 'c'] | ... }) | >>> df.describe() | numeric | count 3.0 | mean 2.0 | std 1.0 | min 1.0 | 25% 1.5 | 50% 2.0 | 75% 2.5 | max 3.0 | | Describing all columns of a ``DataFrame`` regardless of data type. | | >>> df.describe(include='all') | categorical numeric object | count 3 3.0 3 | unique 3 NaN 3 | top f NaN c | freq 1 NaN 1 | mean NaN 2.0 NaN | std NaN 1.0 NaN | min NaN 1.0 NaN | 25% NaN 1.5 NaN | 50% NaN 2.0 NaN | 75% NaN 2.5 NaN | max NaN 3.0 NaN | | Describing a column from a ``DataFrame`` by accessing it as | an attribute. | | >>> df.numeric.describe() | count 3.0 | mean 2.0 | std 1.0 | min 1.0 | 25% 1.5 | 50% 2.0 | 75% 2.5 | max 3.0 | Name: numeric, dtype: float64 | | Including only numeric columns in a ``DataFrame`` description. | | >>> df.describe(include=[np.number]) | numeric | count 3.0 | mean 2.0 | std 1.0 | min 1.0 | 25% 1.5 | 50% 2.0 | 75% 2.5 | max 3.0 | | Including only string columns in a ``DataFrame`` description. | | >>> df.describe(include=[np.object]) | object | count 3 | unique 3 | top c | freq 1 | | Including only categorical columns from a ``DataFrame`` description. | | >>> df.describe(include=['category']) | categorical | count 3 | unique 3 | top f | freq 1 | | Excluding numeric columns from a ``DataFrame`` description. | | >>> df.describe(exclude=[np.number]) | categorical object | count 3 3 | unique 3 3 | top f c | freq 1 1 | | Excluding object columns from a ``DataFrame`` description. | | >>> df.describe(exclude=[np.object]) | categorical numeric | count 3 3.0 | unique 3 NaN | top f NaN | freq 1 NaN | mean NaN 2.0 | std NaN 1.0 | min NaN 1.0 | 25% NaN 1.5 | 50% NaN 2.0 | 75% NaN 2.5 | max NaN 3.0 | | droplevel(self: ~FrameOrSeries, level, axis=0) -> ~FrameOrSeries | Return DataFrame with requested index / column level(s) removed. | | .. versionadded:: 0.24.0 | | Parameters | ---------- | level : int, str, or list-like | If a string is given, must be the name of a level | If list-like, elements must be names or positional indexes | of levels. | | axis : {0 or 'index', 1 or 'columns'}, default 0 | | Returns | ------- | DataFrame | DataFrame with requested index / column level(s) removed. | | Examples | -------- | >>> df = pd.DataFrame([ | ... [1, 2, 3, 4], | ... [5, 6, 7, 8], | ... [9, 10, 11, 12] | ... ]).set_index([0, 1]).rename_axis(['a', 'b']) | | >>> df.columns = pd.MultiIndex.from_tuples([ | ... ('c', 'e'), ('d', 'f') | ... ], names=['level_1', 'level_2']) | | >>> df | level_1 c d | level_2 e f | a b | 1 2 3 4 | 5 6 7 8 | 9 10 11 12 | | >>> df.droplevel('a') | level_1 c d | level_2 e f | b | 2 3 4 | 6 7 8 | 10 11 12 | | >>> df.droplevel('level2', axis=1) | level_1 c d | a b | 1 2 3 4 | 5 6 7 8 | 9 10 11 12 | | equals(self, other) | Test whether two objects contain the same elements. | | This function allows two Series or DataFrames to be compared against | each other to see if they have the same shape and elements. NaNs in | the same location are considered equal. The column headers do not | need to have the same type, but the elements within the columns must | be the same dtype. | | Parameters | ---------- | other : Series or DataFrame | The other Series or DataFrame to be compared with the first. | | Returns | ------- | bool | True if all elements are the same in both objects, False | otherwise. | | See Also | -------- | Series.eq : Compare two Series objects of the same length | and return a Series where each element is True if the element | in each Series is equal, False otherwise. | DataFrame.eq : Compare two DataFrame objects of the same shape and | return a DataFrame where each element is True if the respective | element in each DataFrame is equal, False otherwise. | testing.assert_series_equal : Raises an AssertionError if left and | right are not equal. Provides an easy interface to ignore | inequality in dtypes, indexes and precision among others. | testing.assert_frame_equal : Like assert_series_equal, but targets | DataFrames. | numpy.array_equal : Return True if two arrays have the same shape | and elements, False otherwise. | | Notes | ----- | This function requires that the elements have the same dtype as their | respective elements in the other Series or DataFrame. However, the | column labels do not need to have the same type, as long as they are | still considered equal. | | Examples | -------- | >>> df = pd.DataFrame({1: [10], 2: [20]}) | >>> df | 1 2 | 0 10 20 | | DataFrames df and exactly_equal have the same types and values for | their elements and column labels, which will return True. | | >>> exactly_equal = pd.DataFrame({1: [10], 2: [20]}) | >>> exactly_equal | 1 2 | 0 10 20 | >>> df.equals(exactly_equal) | True | | DataFrames df and different_column_type have the same element | types and values, but have different types for the column labels, | which will still return True. | | >>> different_column_type = pd.DataFrame({1.0: [10], 2.0: [20]}) | >>> different_column_type | 1.0 2.0 | 0 10 20 | >>> df.equals(different_column_type) | True | | DataFrames df and different_data_type have different types for the | same values for their elements, and will return False even though | their column labels are the same values and types. | | >>> different_data_type = pd.DataFrame({1: [10.0], 2: [20.0]}) | >>> different_data_type | 1 2 | 0 10.0 20.0 | >>> df.equals(different_data_type) | False | | ffill(self: ~FrameOrSeries, axis=None, inplace: bool = False, limit=None, downcast=None) -> Union[~FrameOrSeries, NoneType] | Synonym for :meth:`DataFrame.fillna` with ``method='ffill'``. | | Returns | ------- | %(klass)s or None | Object with missing values filled or None if ``inplace=True``. | | filter(self: ~FrameOrSeries, items=None, like: Union[str, NoneType] = None, regex: Union[str, NoneType] = None, axis=None) -> ~FrameOrSeries | Subset the dataframe rows or columns according to the specified index labels. | | Note that this routine does not filter a dataframe on its | contents. The filter is applied to the labels of the index. | | Parameters | ---------- | items : list-like | Keep labels from axis which are in items. | like : str | Keep labels from axis for which "like in label == True". | regex : str (regular expression) | Keep labels from axis for which re.search(regex, label) == True. | axis : {0 or ‘index’, 1 or ‘columns’, None}, default None | The axis to filter on, expressed either as an index (int) | or axis name (str). By default this is the info axis, | 'index' for Series, 'columns' for DataFrame. | | Returns | ------- | same type as input object | | See Also | -------- | DataFrame.loc | | Notes | ----- | The ``items``, ``like``, and ``regex`` parameters are | enforced to be mutually exclusive. | | ``axis`` defaults to the info axis that is used when indexing | with ``[]``. | | Examples | -------- | >>> df = pd.DataFrame(np.array(([1, 2, 3], [4, 5, 6])), | ... index=['mouse', 'rabbit'], | ... columns=['one', 'two', 'three']) | | >>> # select columns by name | >>> df.filter(items=['one', 'three']) | one three | mouse 1 3 | rabbit 4 6 | | >>> # select columns by regular expression | >>> df.filter(regex='e$', axis=1) | one three | mouse 1 3 | rabbit 4 6 | | >>> # select rows containing 'bbi' | >>> df.filter(like='bbi', axis=0) | one two three | rabbit 4 5 6 | | first(self: ~FrameOrSeries, offset) -> ~FrameOrSeries | Method to subset initial periods of time series data based on a date offset. | | Parameters | ---------- | offset : str, DateOffset, dateutil.relativedelta | | Returns | ------- | subset : same type as caller | | Raises | ------ | TypeError | If the index is not a :class:`DatetimeIndex` | | See Also | -------- | last : Select final periods of time series based on a date offset. | at_time : Select values at a particular time of the day. | between_time : Select values between particular times of the day. | | Examples | -------- | >>> i = pd.date_range('2018-04-09', periods=4, freq='2D') | >>> ts = pd.DataFrame({'A': [1,2,3,4]}, index=i) | >>> ts | A | 2018-04-09 1 | 2018-04-11 2 | 2018-04-13 3 | 2018-04-15 4 | | Get the rows for the first 3 days: | | >>> ts.first('3D') | A | 2018-04-09 1 | 2018-04-11 2 | | Notice the data for 3 first calender days were returned, not the first | 3 days observed in the dataset, and therefore data for 2018-04-13 was | not returned. | | first_valid_index(self) | Return index for first non-NA/null value. | | Returns | ------- | scalar : type of index | | Notes | ----- | If all elements are non-NA/null, returns None. | Also returns None for empty Series/DataFrame. | | get(self, key, default=None) | Get item from object for given key (ex: DataFrame column). | | Returns default value if not found. | | Parameters | ---------- | key : object | | Returns | ------- | value : same type as items contained in object | | head(self: ~FrameOrSeries, n: int = 5) -> ~FrameOrSeries | Return the first `n` rows. | | This function returns the first `n` rows for the object based | on position. It is useful for quickly testing if your object | has the right type of data in it. | | For negative values of `n`, this function returns all rows except | the last `n` rows, equivalent to ``df[:-n]``. | | Parameters | ---------- | n : int, default 5 | Number of rows to select. | | Returns | ------- | same type as caller | The first `n` rows of the caller object. | | See Also | -------- | DataFrame.tail: Returns the last `n` rows. | | Examples | -------- | >>> df = pd.DataFrame({'animal': ['alligator', 'bee', 'falcon', 'lion', | ... 'monkey', 'parrot', 'shark', 'whale', 'zebra']}) | >>> df | animal | 0 alligator | 1 bee | 2 falcon | 3 lion | 4 monkey | 5 parrot | 6 shark | 7 whale | 8 zebra | | Viewing the first 5 lines | | >>> df.head() | animal | 0 alligator | 1 bee | 2 falcon | 3 lion | 4 monkey | | Viewing the first `n` lines (three in this case) | | >>> df.head(3) | animal | 0 alligator | 1 bee | 2 falcon | | For negative values of `n` | | >>> df.head(-3) | animal | 0 alligator | 1 bee | 2 falcon | 3 lion | 4 monkey | 5 parrot | | infer_objects(self: ~FrameOrSeries) -> ~FrameOrSeries | Attempt to infer better dtypes for object columns. | | Attempts soft conversion of object-dtyped | columns, leaving non-object and unconvertible | columns unchanged. The inference rules are the | same as during normal Series/DataFrame construction. | | .. versionadded:: 0.21.0 | | Returns | ------- | converted : same type as input object | | See Also | -------- | to_datetime : Convert argument to datetime. | to_timedelta : Convert argument to timedelta. | to_numeric : Convert argument to numeric type. | convert_dtypes : Convert argument to best possible dtype. | | Examples | -------- | >>> df = pd.DataFrame({"A": ["a", 1, 2, 3]}) | >>> df = df.iloc[1:] | >>> df | A | 1 1 | 2 2 | 3 3 | | >>> df.dtypes | A object | dtype: object | | >>> df.infer_objects().dtypes | A int64 | dtype: object | | interpolate(self, method='linear', axis=0, limit=None, inplace=False, limit_direction='forward', limit_area=None, downcast=None, **kwargs) | Interpolate values according to different methods. | | Please note that only ``method='linear'`` is supported for | DataFrame/Series with a MultiIndex. | | Parameters | ---------- | method : str, default 'linear' | Interpolation technique to use. One of: | | * 'linear': Ignore the index and treat the values as equally | spaced. This is the only method supported on MultiIndexes. | * 'time': Works on daily and higher resolution data to interpolate | given length of interval. | * 'index', 'values': use the actual numerical values of the index. | * 'pad': Fill in NaNs using existing values. | * 'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'spline', | 'barycentric', 'polynomial': Passed to | `scipy.interpolate.interp1d`. These methods use the numerical | values of the index. Both 'polynomial' and 'spline' require that | you also specify an `order` (int), e.g. | ``df.interpolate(method='polynomial', order=5)``. | * 'krogh', 'piecewise_polynomial', 'spline', 'pchip', 'akima': | Wrappers around the SciPy interpolation methods of similar | names. See `Notes`. | * 'from_derivatives': Refers to | `scipy.interpolate.BPoly.from_derivatives` which | replaces 'piecewise_polynomial' interpolation method in | scipy 0.18. | axis : {0 or 'index', 1 or 'columns', None}, default None | Axis to interpolate along. | limit : int, optional | Maximum number of consecutive NaNs to fill. Must be greater than | 0. | inplace : bool, default False | Update the data in place if possible. | limit_direction : {'forward', 'backward', 'both'}, default 'forward' | If limit is specified, consecutive NaNs will be filled in this | direction. | limit_area : {`None`, 'inside', 'outside'}, default None | If limit is specified, consecutive NaNs will be filled with this | restriction. | | * ``None``: No fill restriction. | * 'inside': Only fill NaNs surrounded by valid values | (interpolate). | * 'outside': Only fill NaNs outside valid values (extrapolate). | | .. versionadded:: 0.23.0 | | downcast : optional, 'infer' or None, defaults to None | Downcast dtypes if possible. | **kwargs | Keyword arguments to pass on to the interpolating function. | | Returns | ------- | Series or DataFrame | Returns the same object type as the caller, interpolated at | some or all ``NaN`` values. | | See Also | -------- | fillna : Fill missing values using different methods. | scipy.interpolate.Akima1DInterpolator : Piecewise cubic polynomials | (Akima interpolator). | scipy.interpolate.BPoly.from_derivatives : Piecewise polynomial in the | Bernstein basis. | scipy.interpolate.interp1d : Interpolate a 1-D function. | scipy.interpolate.KroghInterpolator : Interpolate polynomial (Krogh | interpolator). | scipy.interpolate.PchipInterpolator : PCHIP 1-d monotonic cubic | interpolation. | scipy.interpolate.CubicSpline : Cubic spline data interpolator. | | Notes | ----- | The 'krogh', 'piecewise_polynomial', 'spline', 'pchip' and 'akima' | methods are wrappers around the respective SciPy implementations of | similar names. These use the actual numerical values of the index. | For more information on their behavior, see the | `SciPy documentation | <http://docs.scipy.org/doc/scipy/reference/interpolate.html#univariate-interpolation>`__ | and `SciPy tutorial | <http://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html>`__. | | Examples | -------- | Filling in ``NaN`` in a :class:`~pandas.Series` via linear | interpolation. | | >>> s = pd.Series([0, 1, np.nan, 3]) | >>> s | 0 0.0 | 1 1.0 | 2 NaN | 3 3.0 | dtype: float64 | >>> s.interpolate() | 0 0.0 | 1 1.0 | 2 2.0 | 3 3.0 | dtype: float64 | | Filling in ``NaN`` in a Series by padding, but filling at most two | consecutive ``NaN`` at a time. | | >>> s = pd.Series([np.nan, "single_one", np.nan, | ... "fill_two_more", np.nan, np.nan, np.nan, | ... 4.71, np.nan]) | >>> s | 0 NaN | 1 single_one | 2 NaN | 3 fill_two_more | 4 NaN | 5 NaN | 6 NaN | 7 4.71 | 8 NaN | dtype: object | >>> s.interpolate(method='pad', limit=2) | 0 NaN | 1 single_one | 2 single_one | 3 fill_two_more | 4 fill_two_more | 5 fill_two_more | 6 NaN | 7 4.71 | 8 4.71 | dtype: object | | Filling in ``NaN`` in a Series via polynomial interpolation or splines: | Both 'polynomial' and 'spline' methods require that you also specify | an ``order`` (int). | | >>> s = pd.Series([0, 2, np.nan, 8]) | >>> s.interpolate(method='polynomial', order=2) | 0 0.000000 | 1 2.000000 | 2 4.666667 | 3 8.000000 | dtype: float64 | | Fill the DataFrame forward (that is, going down) along each column | using linear interpolation. | | Note how the last entry in column 'a' is interpolated differently, | because there is no entry after it to use for interpolation. | Note how the first entry in column 'b' remains ``NaN``, because there | is no entry before it to use for interpolation. | | >>> df = pd.DataFrame([(0.0, np.nan, -1.0, 1.0), | ... (np.nan, 2.0, np.nan, np.nan), | ... (2.0, 3.0, np.nan, 9.0), | ... (np.nan, 4.0, -4.0, 16.0)], | ... columns=list('abcd')) | >>> df | a b c d | 0 0.0 NaN -1.0 1.0 | 1 NaN 2.0 NaN NaN | 2 2.0 3.0 NaN 9.0 | 3 NaN 4.0 -4.0 16.0 | >>> df.interpolate(method='linear', limit_direction='forward', axis=0) | a b c d | 0 0.0 NaN -1.0 1.0 | 1 1.0 2.0 -2.0 5.0 | 2 2.0 3.0 -3.0 9.0 | 3 2.0 4.0 -4.0 16.0 | | Using polynomial interpolation. | | >>> df['d'].interpolate(method='polynomial', order=2) | 0 1.0 | 1 4.0 | 2 9.0 | 3 16.0 | Name: d, dtype: float64 | | last(self: ~FrameOrSeries, offset) -> ~FrameOrSeries | Method to subset final periods of time series data based on a date offset. | | Parameters | ---------- | offset : str, DateOffset, dateutil.relativedelta | | Returns | ------- | subset : same type as caller | | Raises | ------ | TypeError | If the index is not a :class:`DatetimeIndex` | | See Also | -------- | first : Select initial periods of time series based on a date offset. | at_time : Select values at a particular time of the day. | between_time : Select values between particular times of the day. | | Examples | -------- | >>> i = pd.date_range('2018-04-09', periods=4, freq='2D') | >>> ts = pd.DataFrame({'A': [1, 2, 3, 4]}, index=i) | >>> ts | A | 2018-04-09 1 | 2018-04-11 2 | 2018-04-13 3 | 2018-04-15 4 | | Get the rows for the last 3 days: | | >>> ts.last('3D') | A | 2018-04-13 3 | 2018-04-15 4 | | Notice the data for 3 last calender days were returned, not the last | 3 observed days in the dataset, and therefore data for 2018-04-11 was | not returned. | | last_valid_index(self) | Return index for last non-NA/null value. | | Returns | ------- | scalar : type of index | | Notes | ----- | If all elements are non-NA/null, returns None. | Also returns None for empty Series/DataFrame. | | mask(self, cond, other=nan, inplace=False, axis=None, level=None, errors='raise', try_cast=False) | Replace values where the condition is True. | | Parameters | ---------- | cond : bool Series/DataFrame, array-like, or callable | Where `cond` is False, keep the original value. Where | True, replace with corresponding value from `other`. | If `cond` is callable, it is computed on the Series/DataFrame and | should return boolean Series/DataFrame or array. The callable must | not change input Series/DataFrame (though pandas doesn't check it). | other : scalar, Series/DataFrame, or callable | Entries where `cond` is True are replaced with | corresponding value from `other`. | If other is callable, it is computed on the Series/DataFrame and | should return scalar or Series/DataFrame. The callable must not | change input Series/DataFrame (though pandas doesn't check it). | inplace : bool, default False | Whether to perform the operation in place on the data. | axis : int, default None | Alignment axis if needed. | level : int, default None | Alignment level if needed. | errors : str, {'raise', 'ignore'}, default 'raise' | Note that currently this parameter won't affect | the results and will always coerce to a suitable dtype. | | - 'raise' : allow exceptions to be raised. | - 'ignore' : suppress exceptions. On error return original object. | | try_cast : bool, default False | Try to cast the result back to the input type (if possible). | | Returns | ------- | Same type as caller | | See Also | -------- | :func:`DataFrame.where` : Return an object of same shape as | self. | | Notes | ----- | The mask method is an application of the if-then idiom. For each | element in the calling DataFrame, if ``cond`` is ``False`` the | element is used; otherwise the corresponding element from the DataFrame | ``other`` is used. | | The signature for :func:`DataFrame.where` differs from | :func:`numpy.where`. Roughly ``df1.where(m, df2)`` is equivalent to | ``np.where(m, df1, df2)``. | | For further details and examples see the ``mask`` documentation in | :ref:`indexing <indexing.where_mask>`. | | Examples | -------- | >>> s = pd.Series(range(5)) | >>> s.where(s > 0) | 0 NaN | 1 1.0 | 2 2.0 | 3 3.0 | 4 4.0 | dtype: float64 | | >>> s.mask(s > 0) | 0 0.0 | 1 NaN | 2 NaN | 3 NaN | 4 NaN | dtype: float64 | | >>> s.where(s > 1, 10) | 0 10 | 1 10 | 2 2 | 3 3 | 4 4 | dtype: int64 | | >>> df = pd.DataFrame(np.arange(10).reshape(-1, 2), columns=['A', 'B']) | >>> df | A B | 0 0 1 | 1 2 3 | 2 4 5 | 3 6 7 | 4 8 9 | >>> m = df % 3 == 0 | >>> df.where(m, -df) | A B | 0 0 -1 | 1 -2 3 | 2 -4 -5 | 3 6 -7 | 4 -8 9 | >>> df.where(m, -df) == np.where(m, df, -df) | A B | 0 True True | 1 True True | 2 True True | 3 True True | 4 True True | >>> df.where(m, -df) == df.mask(~m, -df) | A B | 0 True True | 1 True True | 2 True True | 3 True True | 4 True True | | pct_change(self: ~FrameOrSeries, periods=1, fill_method='pad', limit=None, freq=None, **kwargs) -> ~FrameOrSeries | Percentage change between the current and a prior element. | | Computes the percentage change from the immediately previous row by | default. This is useful in comparing the percentage of change in a time | series of elements. | | Parameters | ---------- | periods : int, default 1 | Periods to shift for forming percent change. | fill_method : str, default 'pad' | How to handle NAs before computing percent changes. | limit : int, default None | The number of consecutive NAs to fill before stopping. | freq : DateOffset, timedelta, or str, optional | Increment to use from time series API (e.g. 'M' or BDay()). | **kwargs | Additional keyword arguments are passed into | `DataFrame.shift` or `Series.shift`. | | Returns | ------- | chg : Series or DataFrame | The same type as the calling object. | | See Also | -------- | Series.diff : Compute the difference of two elements in a Series. | DataFrame.diff : Compute the difference of two elements in a DataFrame. | Series.shift : Shift the index by some number of periods. | DataFrame.shift : Shift the index by some number of periods. | | Examples | -------- | **Series** | | >>> s = pd.Series([90, 91, 85]) | >>> s | 0 90 | 1 91 | 2 85 | dtype: int64 | | >>> s.pct_change() | 0 NaN | 1 0.011111 | 2 -0.065934 | dtype: float64 | | >>> s.pct_change(periods=2) | 0 NaN | 1 NaN | 2 -0.055556 | dtype: float64 | | See the percentage change in a Series where filling NAs with last | valid observation forward to next valid. | | >>> s = pd.Series([90, 91, None, 85]) | >>> s | 0 90.0 | 1 91.0 | 2 NaN | 3 85.0 | dtype: float64 | | >>> s.pct_change(fill_method='ffill') | 0 NaN | 1 0.011111 | 2 0.000000 | 3 -0.065934 | dtype: float64 | | **DataFrame** | | Percentage change in French franc, Deutsche Mark, and Italian lira from | 1980-01-01 to 1980-03-01. | | >>> df = pd.DataFrame({ | ... 'FR': [4.0405, 4.0963, 4.3149], | ... 'GR': [1.7246, 1.7482, 1.8519], | ... 'IT': [804.74, 810.01, 860.13]}, | ... index=['1980-01-01', '1980-02-01', '1980-03-01']) | >>> df | FR GR IT | 1980-01-01 4.0405 1.7246 804.74 | 1980-02-01 4.0963 1.7482 810.01 | 1980-03-01 4.3149 1.8519 860.13 | | >>> df.pct_change() | FR GR IT | 1980-01-01 NaN NaN NaN | 1980-02-01 0.013810 0.013684 0.006549 | 1980-03-01 0.053365 0.059318 0.061876 | | Percentage of change in GOOG and APPL stock volume. Shows computing | the percentage change between columns. | | >>> df = pd.DataFrame({ | ... '2016': [1769950, 30586265], | ... '2015': [1500923, 40912316], | ... '2014': [1371819, 41403351]}, | ... index=['GOOG', 'APPL']) | >>> df | 2016 2015 2014 | GOOG 1769950 1500923 1371819 | APPL 30586265 40912316 41403351 | | >>> df.pct_change(axis='columns') | 2016 2015 2014 | GOOG NaN -0.151997 -0.086016 | APPL NaN 0.337604 0.012002 | | pipe(self, func, *args, **kwargs) | Apply func(self, \*args, \*\*kwargs). | | Parameters | ---------- | func : function | Function to apply to the Series/DataFrame. | ``args``, and ``kwargs`` are passed into ``func``. | Alternatively a ``(callable, data_keyword)`` tuple where | ``data_keyword`` is a string indicating the keyword of | ``callable`` that expects the Series/DataFrame. | args : iterable, optional | Positional arguments passed into ``func``. | kwargs : mapping, optional | A dictionary of keyword arguments passed into ``func``. | | Returns | ------- | object : the return type of ``func``. | | See Also | -------- | DataFrame.apply | DataFrame.applymap | Series.map | | Notes | ----- | | Use ``.pipe`` when chaining together functions that expect | Series, DataFrames or GroupBy objects. Instead of writing | | >>> f(g(h(df), arg1=a), arg2=b, arg3=c) | | You can write | | >>> (df.pipe(h) | ... .pipe(g, arg1=a) | ... .pipe(f, arg2=b, arg3=c) | ... ) | | If you have a function that takes the data as (say) the second | argument, pass a tuple indicating which keyword expects the | data. For example, suppose ``f`` takes its data as ``arg2``: | | >>> (df.pipe(h) | ... .pipe(g, arg1=a) | ... .pipe((f, 'arg2'), arg1=a, arg3=c) | ... ) | | pop(self: ~FrameOrSeries, item) -> ~FrameOrSeries | Return item and drop from frame. Raise KeyError if not found. | | Parameters | ---------- | item : str | Label of column to be popped. | | Returns | ------- | Series | | Examples | -------- | >>> df = pd.DataFrame([('falcon', 'bird', 389.0), | ... ('parrot', 'bird', 24.0), | ... ('lion', 'mammal', 80.5), | ... ('monkey', 'mammal', np.nan)], | ... columns=('name', 'class', 'max_speed')) | >>> df | name class max_speed | 0 falcon bird 389.0 | 1 parrot bird 24.0 | 2 lion mammal 80.5 | 3 monkey mammal NaN | | >>> df.pop('class') | 0 bird | 1 bird | 2 mammal | 3 mammal | Name: class, dtype: object | | >>> df | name max_speed | 0 falcon 389.0 | 1 parrot 24.0 | 2 lion 80.5 | 3 monkey NaN | | rank(self: ~FrameOrSeries, axis=0, method: str = 'average', numeric_only: Union[bool, NoneType] = None, na_option: str = 'keep', ascending: bool = True, pct: bool = False) -> ~FrameOrSeries | Compute numerical data ranks (1 through n) along axis. | | By default, equal values are assigned a rank that is the average of the | ranks of those values. | | Parameters | ---------- | axis : {0 or 'index', 1 or 'columns'}, default 0 | Index to direct ranking. | method : {'average', 'min', 'max', 'first', 'dense'}, default 'average' | How to rank the group of records that have the same value (i.e. ties): | | * average: average rank of the group | * min: lowest rank in the group | * max: highest rank in the group | * first: ranks assigned in order they appear in the array | * dense: like 'min', but rank always increases by 1 between groups. | | numeric_only : bool, optional | For DataFrame objects, rank only numeric columns if set to True. | na_option : {'keep', 'top', 'bottom'}, default 'keep' | How to rank NaN values: | | * keep: assign NaN rank to NaN values | * top: assign smallest rank to NaN values if ascending | * bottom: assign highest rank to NaN values if ascending. | | ascending : bool, default True | Whether or not the elements should be ranked in ascending order. | pct : bool, default False | Whether or not to display the returned rankings in percentile | form. | | Returns | ------- | same type as caller | Return a Series or DataFrame with data ranks as values. | | See Also | -------- | core.groupby.GroupBy.rank : Rank of values within each group. | | Examples | -------- | | >>> df = pd.DataFrame(data={'Animal': ['cat', 'penguin', 'dog', | ... 'spider', 'snake'], | ... 'Number_legs': [4, 2, 4, 8, np.nan]}) | >>> df | Animal Number_legs | 0 cat 4.0 | 1 penguin 2.0 | 2 dog 4.0 | 3 spider 8.0 | 4 snake NaN | | The following example shows how the method behaves with the above | parameters: | | * default_rank: this is the default behaviour obtained without using | any parameter. | * max_rank: setting ``method = 'max'`` the records that have the | same values are ranked using the highest rank (e.g.: since 'cat' | and 'dog' are both in the 2nd and 3rd position, rank 3 is assigned.) | * NA_bottom: choosing ``na_option = 'bottom'``, if there are records | with NaN values they are placed at the bottom of the ranking. | * pct_rank: when setting ``pct = True``, the ranking is expressed as | percentile rank. | | >>> df['default_rank'] = df['Number_legs'].rank() | >>> df['max_rank'] = df['Number_legs'].rank(method='max') | >>> df['NA_bottom'] = df['Number_legs'].rank(na_option='bottom') | >>> df['pct_rank'] = df['Number_legs'].rank(pct=True) | >>> df | Animal Number_legs default_rank max_rank NA_bottom pct_rank | 0 cat 4.0 2.5 3.0 2.5 0.625 | 1 penguin 2.0 1.0 1.0 1.0 0.250 | 2 dog 4.0 2.5 3.0 2.5 0.625 | 3 spider 8.0 4.0 4.0 4.0 1.000 | 4 snake NaN NaN NaN 5.0 NaN | | reindex_like(self: ~FrameOrSeries, other, method: Union[str, NoneType] = None, copy: bool = True, limit=None, tolerance=None) -> ~FrameOrSeries | Return an object with matching indices as other object. | | Conform the object to the same index on all axes. Optional | filling logic, placing 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 | ---------- | other : Object of the same data type | Its row and column indices are used to define the new indices | of this object. | 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. | limit : int, default None | Maximum number of consecutive labels to fill for inexact matches. | 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 or DataFrame | Same type as caller, but with changed indices on each axis. | | See Also | -------- | DataFrame.set_index : Set row labels. | DataFrame.reset_index : Remove row labels or move them to new columns. | DataFrame.reindex : Change to new indices or expand indices. | | Notes | ----- | Same as calling | ``.reindex(index=other.index, columns=other.columns,...)``. | | Examples | -------- | >>> df1 = pd.DataFrame([[24.3, 75.7, 'high'], | ... [31, 87.8, 'high'], | ... [22, 71.6, 'medium'], | ... [35, 95, 'medium']], | ... columns=['temp_celsius', 'temp_fahrenheit', | ... 'windspeed'], | ... index=pd.date_range(start='2014-02-12', | ... end='2014-02-15', freq='D')) | | >>> df1 | temp_celsius temp_fahrenheit windspeed | 2014-02-12 24.3 75.7 high | 2014-02-13 31.0 87.8 high | 2014-02-14 22.0 71.6 medium | 2014-02-15 35.0 95.0 medium | | >>> df2 = pd.DataFrame([[28, 'low'], | ... [30, 'low'], | ... [35.1, 'medium']], | ... columns=['temp_celsius', 'windspeed'], | ... index=pd.DatetimeIndex(['2014-02-12', '2014-02-13', | ... '2014-02-15'])) | | >>> df2 | temp_celsius windspeed | 2014-02-12 28.0 low | 2014-02-13 30.0 low | 2014-02-15 35.1 medium | | >>> df2.reindex_like(df1) | temp_celsius temp_fahrenheit windspeed | 2014-02-12 28.0 NaN low | 2014-02-13 30.0 NaN low | 2014-02-14 NaN NaN NaN | 2014-02-15 35.1 NaN medium | | rename_axis(self, mapper=None, index=None, columns=None, axis=None, copy=True, inplace=False) | Set the name of the axis for the index or columns. | | Parameters | ---------- | mapper : scalar, list-like, optional | Value to set the axis name attribute. | index, columns : scalar, list-like, dict-like or function, optional | A scalar, list-like, dict-like or functions transformations to | apply to that axis' values. | | Use either ``mapper`` and ``axis`` to | specify the axis to target with ``mapper``, or ``index`` | and/or ``columns``. | | .. versionchanged:: 0.24.0 | | axis : {0 or 'index', 1 or 'columns'}, default 0 | The axis to rename. | copy : bool, default True | Also copy underlying data. | inplace : bool, default False | Modifies the object directly, instead of creating a new Series | or DataFrame. | | Returns | ------- | Series, DataFrame, or None | The same type as the caller or None if `inplace` is True. | | See Also | -------- | Series.rename : Alter Series index labels or name. | DataFrame.rename : Alter DataFrame index labels or name. | Index.rename : Set new names on index. | | Notes | ----- | ``DataFrame.rename_axis`` supports two calling conventions | | * ``(index=index_mapper, columns=columns_mapper, ...)`` | * ``(mapper, axis={'index', 'columns'}, ...)`` | | The first calling convention will only modify the names of | the index and/or the names of the Index object that is the columns. | In this case, the parameter ``copy`` is ignored. | | The second calling convention will modify the names of the | the corresponding index if mapper is a list or a scalar. | However, if mapper is dict-like or a function, it will use the | deprecated behavior of modifying the axis *labels*. | | We *highly* recommend using keyword arguments to clarify your | intent. | | Examples | -------- | **Series** | | >>> s = pd.Series(["dog", "cat", "monkey"]) | >>> s | 0 dog | 1 cat | 2 monkey | dtype: object | >>> s.rename_axis("animal") | animal | 0 dog | 1 cat | 2 monkey | dtype: object | | **DataFrame** | | >>> df = pd.DataFrame({"num_legs": [4, 4, 2], | ... "num_arms": [0, 0, 2]}, | ... ["dog", "cat", "monkey"]) | >>> df | num_legs num_arms | dog 4 0 | cat 4 0 | monkey 2 2 | >>> df = df.rename_axis("animal") | >>> df | num_legs num_arms | animal | dog 4 0 | cat 4 0 | monkey 2 2 | >>> df = df.rename_axis("limbs", axis="columns") | >>> df | limbs num_legs num_arms | animal | dog 4 0 | cat 4 0 | monkey 2 2 | | **MultiIndex** | | >>> df.index = pd.MultiIndex.from_product([['mammal'], | ... ['dog', 'cat', 'monkey']], | ... names=['type', 'name']) | >>> df | limbs num_legs num_arms | type name | mammal dog 4 0 | cat 4 0 | monkey 2 2 | | >>> df.rename_axis(index={'type': 'class'}) | limbs num_legs num_arms | class name | mammal dog 4 0 | cat 4 0 | monkey 2 2 | | >>> df.rename_axis(columns=str.upper) | LIMBS num_legs num_arms | type name | mammal dog 4 0 | cat 4 0 | monkey 2 2 | | resample(self, rule, axis=0, closed: Union[str, NoneType] = None, label: Union[str, NoneType] = None, convention: str = 'start', kind: Union[str, NoneType] = None, loffset=None, base: int = 0, on=None, level=None) | Resample time-series data. | | Convenience method for frequency conversion and resampling of time | series. Object must have a datetime-like index (`DatetimeIndex`, | `PeriodIndex`, or `TimedeltaIndex`), or pass datetime-like values | to the `on` or `level` keyword. | | Parameters | ---------- | rule : DateOffset, Timedelta or str | The offset string or object representing target conversion. | axis : {0 or 'index', 1 or 'columns'}, default 0 | Which axis to use for up- or down-sampling. For `Series` this | will default to 0, i.e. along the rows. Must be | `DatetimeIndex`, `TimedeltaIndex` or `PeriodIndex`. | closed : {'right', 'left'}, default None | Which side of bin interval is closed. The default is 'left' | for all frequency offsets except for 'M', 'A', 'Q', 'BM', | 'BA', 'BQ', and 'W' which all have a default of 'right'. | label : {'right', 'left'}, default None | Which bin edge label to label bucket with. The default is 'left' | for all frequency offsets except for 'M', 'A', 'Q', 'BM', | 'BA', 'BQ', and 'W' which all have a default of 'right'. | convention : {'start', 'end', 's', 'e'}, default 'start' | For `PeriodIndex` only, controls whether to use the start or | end of `rule`. | kind : {'timestamp', 'period'}, optional, default None | Pass 'timestamp' to convert the resulting index to a | `DateTimeIndex` or 'period' to convert it to a `PeriodIndex`. | By default the input representation is retained. | loffset : timedelta, default None | Adjust the resampled time labels. | base : int, default 0 | For frequencies that evenly subdivide 1 day, the "origin" of the | aggregated intervals. For example, for '5min' frequency, base could | range from 0 through 4. Defaults to 0. | on : str, optional | For a DataFrame, column to use instead of index for resampling. | Column must be datetime-like. | | level : str or int, optional | For a MultiIndex, level (name or number) to use for | resampling. `level` must be datetime-like. | | Returns | ------- | Resampler object | | See Also | -------- | groupby : Group by mapping, function, label, or list of labels. | Series.resample : Resample a Series. | DataFrame.resample: Resample a DataFrame. | | Notes | ----- | See the `user guide | <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#resampling>`_ | for more. | | To learn more about the offset strings, please see `this link | <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#dateoffset-objects>`__. | | Examples | -------- | | Start by creating a series with 9 one minute timestamps. | | >>> index = pd.date_range('1/1/2000', periods=9, freq='T') | >>> series = pd.Series(range(9), index=index) | >>> series | 2000-01-01 00:00:00 0 | 2000-01-01 00:01:00 1 | 2000-01-01 00:02:00 2 | 2000-01-01 00:03:00 3 | 2000-01-01 00:04:00 4 | 2000-01-01 00:05:00 5 | 2000-01-01 00:06:00 6 | 2000-01-01 00:07:00 7 | 2000-01-01 00:08:00 8 | Freq: T, dtype: int64 | | Downsample the series into 3 minute bins and sum the values | of the timestamps falling into a bin. | | >>> series.resample('3T').sum() | 2000-01-01 00:00:00 3 | 2000-01-01 00:03:00 12 | 2000-01-01 00:06:00 21 | Freq: 3T, dtype: int64 | | Downsample the series into 3 minute bins as above, but label each | bin using the right edge instead of the left. Please note that the | value in the bucket used as the label is not included in the bucket, | which it labels. For example, in the original series the | bucket ``2000-01-01 00:03:00`` contains the value 3, but the summed | value in the resampled bucket with the label ``2000-01-01 00:03:00`` | does not include 3 (if it did, the summed value would be 6, not 3). | To include this value close the right side of the bin interval as | illustrated in the example below this one. | | >>> series.resample('3T', label='right').sum() | 2000-01-01 00:03:00 3 | 2000-01-01 00:06:00 12 | 2000-01-01 00:09:00 21 | Freq: 3T, dtype: int64 | | Downsample the series into 3 minute bins as above, but close the right | side of the bin interval. | | >>> series.resample('3T', label='right', closed='right').sum() | 2000-01-01 00:00:00 0 | 2000-01-01 00:03:00 6 | 2000-01-01 00:06:00 15 | 2000-01-01 00:09:00 15 | Freq: 3T, dtype: int64 | | Upsample the series into 30 second bins. | | >>> series.resample('30S').asfreq()[0:5] # Select first 5 rows | 2000-01-01 00:00:00 0.0 | 2000-01-01 00:00:30 NaN | 2000-01-01 00:01:00 1.0 | 2000-01-01 00:01:30 NaN | 2000-01-01 00:02:00 2.0 | Freq: 30S, dtype: float64 | | Upsample the series into 30 second bins and fill the ``NaN`` | values using the ``pad`` method. | | >>> series.resample('30S').pad()[0:5] | 2000-01-01 00:00:00 0 | 2000-01-01 00:00:30 0 | 2000-01-01 00:01:00 1 | 2000-01-01 00:01:30 1 | 2000-01-01 00:02:00 2 | Freq: 30S, dtype: int64 | | Upsample the series into 30 second bins and fill the | ``NaN`` values using the ``bfill`` method. | | >>> series.resample('30S').bfill()[0:5] | 2000-01-01 00:00:00 0 | 2000-01-01 00:00:30 1 | 2000-01-01 00:01:00 1 | 2000-01-01 00:01:30 2 | 2000-01-01 00:02:00 2 | Freq: 30S, dtype: int64 | | Pass a custom function via ``apply`` | | >>> def custom_resampler(array_like): | ... return np.sum(array_like) + 5 | ... | >>> series.resample('3T').apply(custom_resampler) | 2000-01-01 00:00:00 8 | 2000-01-01 00:03:00 17 | 2000-01-01 00:06:00 26 | Freq: 3T, dtype: int64 | | For a Series with a PeriodIndex, the keyword `convention` can be | used to control whether to use the start or end of `rule`. | | Resample a year by quarter using 'start' `convention`. Values are | assigned to the first quarter of the period. | | >>> s = pd.Series([1, 2], index=pd.period_range('2012-01-01', | ... freq='A', | ... periods=2)) | >>> s | 2012 1 | 2013 2 | Freq: A-DEC, dtype: int64 | >>> s.resample('Q', convention='start').asfreq() | 2012Q1 1.0 | 2012Q2 NaN | 2012Q3 NaN | 2012Q4 NaN | 2013Q1 2.0 | 2013Q2 NaN | 2013Q3 NaN | 2013Q4 NaN | Freq: Q-DEC, dtype: float64 | | Resample quarters by month using 'end' `convention`. Values are | assigned to the last month of the period. | | >>> q = pd.Series([1, 2, 3, 4], index=pd.period_range('2018-01-01', | ... freq='Q', | ... periods=4)) | >>> q | 2018Q1 1 | 2018Q2 2 | 2018Q3 3 | 2018Q4 4 | Freq: Q-DEC, dtype: int64 | >>> q.resample('M', convention='end').asfreq() | 2018-03 1.0 | 2018-04 NaN | 2018-05 NaN | 2018-06 2.0 | 2018-07 NaN | 2018-08 NaN | 2018-09 3.0 | 2018-10 NaN | 2018-11 NaN | 2018-12 4.0 | Freq: M, dtype: float64 | | For DataFrame objects, the keyword `on` can be used to specify the | column instead of the index for resampling. | | >>> d = dict({'price': [10, 11, 9, 13, 14, 18, 17, 19], | ... 'volume': [50, 60, 40, 100, 50, 100, 40, 50]}) | >>> df = pd.DataFrame(d) | >>> df['week_starting'] = pd.date_range('01/01/2018', | ... periods=8, | ... freq='W') | >>> df | price volume week_starting | 0 10 50 2018-01-07 | 1 11 60 2018-01-14 | 2 9 40 2018-01-21 | 3 13 100 2018-01-28 | 4 14 50 2018-02-04 | 5 18 100 2018-02-11 | 6 17 40 2018-02-18 | 7 19 50 2018-02-25 | >>> df.resample('M', on='week_starting').mean() | price volume | week_starting | 2018-01-31 10.75 62.5 | 2018-02-28 17.00 60.0 | | For a DataFrame with MultiIndex, the keyword `level` can be used to | specify on which level the resampling needs to take place. | | >>> days = pd.date_range('1/1/2000', periods=4, freq='D') | >>> d2 = dict({'price': [10, 11, 9, 13, 14, 18, 17, 19], | ... 'volume': [50, 60, 40, 100, 50, 100, 40, 50]}) | >>> df2 = pd.DataFrame(d2, | ... index=pd.MultiIndex.from_product([days, | ... ['morning', | ... 'afternoon']] | ... )) | >>> df2 | price volume | 2000-01-01 morning 10 50 | afternoon 11 60 | 2000-01-02 morning 9 40 | afternoon 13 100 | 2000-01-03 morning 14 50 | afternoon 18 100 | 2000-01-04 morning 17 40 | afternoon 19 50 | >>> df2.resample('D', level=0).sum() | price volume | 2000-01-01 21 110 | 2000-01-02 22 140 | 2000-01-03 32 150 | 2000-01-04 36 90 | | sample(self: ~FrameOrSeries, n=None, frac=None, replace=False, weights=None, random_state=None, axis=None) -> ~FrameOrSeries | Return a random sample of items from an axis of object. | | You can use `random_state` for reproducibility. | | Parameters | ---------- | n : int, optional | Number of items from axis to return. Cannot be used with `frac`. | Default = 1 if `frac` = None. | frac : float, optional | Fraction of axis items to return. Cannot be used with `n`. | replace : bool, default False | Allow or disallow sampling of the same row more than once. | weights : str or ndarray-like, optional | Default 'None' results in equal probability weighting. | If passed a Series, will align with target object on index. Index | values in weights not found in sampled object will be ignored and | index values in sampled object not in weights will be assigned | weights of zero. | If called on a DataFrame, will accept the name of a column | when axis = 0. | Unless weights are a Series, weights must be same length as axis | being sampled. | If weights do not sum to 1, they will be normalized to sum to 1. | Missing values in the weights column will be treated as zero. | Infinite values not allowed. | random_state : int or numpy.random.RandomState, optional | Seed for the random number generator (if int), or numpy RandomState | object. | axis : {0 or ‘index’, 1 or ‘columns’, None}, default None | Axis to sample. Accepts axis number or name. Default is stat axis | for given data type (0 for Series and DataFrames). | | Returns | ------- | Series or DataFrame | A new object of same type as caller containing `n` items randomly |