Detail: IndexHierarchy: Method
Overview: IndexHierarchy: Method
- IndexHierarchy.__array__(dtype=None)
Support the __array__ interface, returning an array of values.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.__array__() [[ 0 1024 32] [ 1 -2048 32] [ 1 1024 32]]
- IndexHierarchy.__array_ufunc__(ufunc, method, *args, **kwargs)
Support for NumPy elements or arrays on the left hand of binary operators.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> np.array((0, 1, 0)) * ih [[ 0 1024 0] [ 0 -2048 0] [ 0 1024 0]]
- IndexHierarchy.__bool__()
Raises ValueError to prohibit ambiguous use of truthy evaluation.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> bool(ih) ErrorNotTruthy('The truth value of a container is ambiguous. For a truthy indicator of non-empty status, use the `size` attribute.')
- IndexHierarchy.__copy__()[source]
Return a shallow copy of this IndexHierarchy.
>>> import copy >>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> copy.copy(ih) <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64>
- IndexHierarchy.__deepcopy__(memo)[source]
Return a deep copy of this IndexHierarchy.
>>> import copy >>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> copy.deepcopy(ih) <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64>
- IndexHierarchy.__len__()[source]
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> len(ih) 3
- IndexHierarchy.all(axis=0, skipna=True, out=None)
Logical
and
over values along the specified axis.- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((False, True, True), (True, True, True), (False, True, False)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> False True True True True True False True False <bool> <bool> <bool> >>> ih.all() NotImplementedError('<function ufunc_all at 0x7f9ba0b8d9e0> for IndexHierarchy is not defined; convert to `Frame`.')
- IndexHierarchy.any(axis=0, skipna=True, out=None)
Logical
or
over values along the specified axis.- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((False, True, True), (True, True, True), (False, True, False)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> False True True True True True False True False <bool> <bool> <bool> >>> ih.any() NotImplementedError('<function ufunc_any at 0x7f9ba0b8da80> for IndexHierarchy is not defined; convert to `Frame`.')
- IndexHierarchy.astype[key](dtypes, *, consolidate_blocks)
- astype
Retype one or more depths. Can be used as as function to retype the entire
IndexHierarchy
; alternatively, a__getitem__
interface permits retyping selected depths.- Parameters:
dtype – A value suitable for specyfying a NumPy dtype, such as a Python type (float), NumPy array protocol strings (‘f8’), or a dtype instance.
- InterfaceIndexHierarchyAsType.__getitem__(key)[source]
Selector of columns by label.
- Parameters:
key – A loc selector, either a label, a list of labels, a slice of labels, or a Boolean array.
>>> ih = sf.IndexHierarchy.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> a 1024 1517-04-01 a 2048 1789-12-31 b 0 1620-11-21 <<U1> <int64> <datetime64[D]> >>> ih.astype[1](bool) <IndexHierarchy: ('x', 'y', 'z')> a True 1517-04-01 a True 1789-12-31 b False 1620-11-21 <<U1> <bool> <datetime64[D]>
- IndexHierarchy.astype(dtype, *, consolidate_blocks)
- astype
Retype one or more depths. Can be used as as function to retype the entire
IndexHierarchy
; alternatively, a__getitem__
interface permits retyping selected depths.- Parameters:
dtype – A value suitable for specyfying a NumPy dtype, such as a Python type (float), NumPy array protocol strings (‘f8’), or a dtype instance.
- InterfaceIndexHierarchyAsType.__call__(dtype, *, consolidate_blocks=False)[source]
Apply a single
dtype
to all columns.
>>> ih = sf.IndexHierarchy.from_labels(((False, True, True), (True, True, True), (False, True, False)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> False True True True True True False True False <bool> <bool> <bool> >>> ih.astype(str) <IndexHierarchy: ('x', 'y', 'z')> False True True True True True False True False <<U5> <<U5> <<U5>
- IndexHierarchy.copy()[source]
Return a shallow copy of this IndexHierarchy.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.copy() <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64>
- IndexHierarchy.cumprod(axis=0, skipna=True)
Return the cumulative product over the specified axis.
- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.cumprod() NotImplementedError('<function cumprod at 0x7f9bd8bda840> for IndexHierarchy is not defined; convert to `Frame`.')
- IndexHierarchy.cumsum(axis=0, skipna=True)
Return the cumulative sum over the specified axis.
- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.cumsum() NotImplementedError('<function cumsum at 0x7f9bd8bda0c0> for IndexHierarchy is not defined; convert to `Frame`.')
- IndexHierarchy.difference(*others)[source]
Perform difference with another Index, container, or NumPy array. Retains order.
>>> ih1 = sf.IndexHierarchy.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x') >>> ih1 <IndexHierarchy: x> a 1024 True a 2048 True a 2048 False <<U1> <int64> <bool> >>> ih2 = sf.IndexHierarchy.from_labels((('a', 1024, True), ('b', 1024, True)), name='y') >>> ih2 <IndexHierarchy: y> a 1024 True b 1024 True <<U1> <int64> <bool> >>> ih1.difference(ih2) <IndexHierarchy> a 2048 False a 2048 True <<U1> <int64> <bool>
- IndexHierarchy.dropfalsy(*, condition=<function all>)[source]
Return a new obj:IndexHierarchy after removing labels where any or all values are falsy. The condition is determined by a NumPy ufunc that process the Boolean array returned by
isna()
; the default isnp.all
.- Parameters:
* –
condition –
>>> ih = sf.IndexHierarchy.from_labels((('a', 1024, True), ('', 0, False), ('b', 1024, True)), name='x') >>> ih <IndexHierarchy: x> a 1024 True 0 False b 1024 True <<U1> <int64> <bool> >>> ih.dropfalsy() <IndexHierarchy: x> a 1024 True b 1024 True <<U1> <int64> <bool>
- IndexHierarchy.dropna(*, condition=<function all>)[source]
Return a new obj:IndexHierarchy after removing labels where any or all values are NA (NaN or None). The condition is determined by a NumPy ufunc that process the Boolean array returned by
isna()
; the default isnp.all
.- Parameters:
* –
condition –
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024), (1, 2048), (np.nan, np.nan)), name=('x', 'y')) >>> ih <IndexHierarchy: ('x', 'y')> 0.0 1024.0 1.0 2048.0 nan nan <float64> <float64> >>> ih.dropna() <IndexHierarchy: ('x', 'y')> 0.0 1024.0 1.0 2048.0 <float64> <float64>
- IndexHierarchy.equals(other, *, compare_name=False, compare_dtype=False, compare_class=False, skipna=True)[source]
Return a
bool
from comparison to any other object.- Parameters:
compare_name – Include equality of the container’s name (and all composed containers) in the comparison.
compare_dtype – Include equality of the container’s dtype (and all composed containers) in the comparison.
compare_class – Include equality of the container’s class (and all composed containers) in the comparison.
skipna – If True, comparisons between missing values are equal.
>>> ih1 = sf.IndexHierarchy.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x') >>> ih1 <IndexHierarchy: x> a 1024 True a 2048 True a 2048 False <<U1> <int64> <bool> >>> ih2 = sf.IndexHierarchy.from_labels((('a', 1024, True), ('b', 1024, True)), name='y') >>> ih2 <IndexHierarchy: y> a 1024 True b 1024 True <<U1> <int64> <bool> >>> ih1.equals(ih2) False
- IndexHierarchy.fillfalsy(value)[source]
Return an
IndexHierarchy
after replacing falsy values with the supplied value.- Parameters:
value – Value to be used to replace missing values (NaN or None).
>>> ih = sf.IndexHierarchy.from_labels((('a', 1024, True), ('', 0, False), ('b', 1024, True)), name='x') >>> ih <IndexHierarchy: x> a 1024 True 0 False b 1024 True <<U1> <int64> <bool> >>> ih.fillfalsy(-1) <IndexHierarchy: x> a 1024 True -1 -1 -1 b 1024 True <object> <int64> <object>
- IndexHierarchy.fillna(value)[source]
Return an
IndexHierarchy
after replacing NA (NaN or None) with the supplied value.- Parameters:
value – Value to be used to replace missing values (NaN or None).
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024), (1, 2048), (np.nan, np.nan)), name=('x', 'y')) >>> ih <IndexHierarchy: ('x', 'y')> 0.0 1024.0 1.0 2048.0 nan nan <float64> <float64> >>> ih.fillna(0) <IndexHierarchy: ('x', 'y')> 0.0 1024.0 1.0 2048.0 0.0 0.0 <float64> <float64>
- IndexHierarchy.flat()[source]
Return a flat, one-dimensional index of tuples for each level.
>>> ih = sf.IndexHierarchy.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> a 1024 1517-04-01 a 2048 1789-12-31 b 0 1620-11-21 <<U1> <int64> <datetime64[D]> >>> ih.flat().display_wide() <Index: ('x', 'y', 'z')> ('a', 1024, numpy.datetime64('1517-04-01')) ('a', 2048, numpy.datetime64('1789-12-31')) ('b', 0, numpy.datetime64('1620-11-21')) <object>
- IndexHierarchy.head(count=5)
Return a
Index
consisting only of the top elements as specified bycount
.- Parameters:
count – Number of elements to be returned from the top of the
Index
>>> ih = sf.IndexHierarchy.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate)) >>> ih <IndexHierarchy: x> a 1517-04-01 a 1620-11-21 b 1517-04-01 b 1620-11-21 c 1517-04-01 c 1620-11-21 <<U1> <datetime64[D]> >>> ih.head(2) <IndexHierarchy: x> a 1517-04-01 a 1620-11-21 <<U1> <datetime64[D]>
- IndexHierarchy.iloc_searchsorted(values, *, side_left=True)[source]
Given a sorted
Series
, return the iloc (integer) position(s) at which insertion invalues
would retain sort order.- Parameters:
values – a single value, or iterable of values.
side_left – If True, the index of the first suitable location found is given, else return the last such index. If matching an existing value, side_left==True will return that position, side_left==Right will return the next position (or the length).
>>> ih = sf.IndexHierarchy.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate)) >>> ih <IndexHierarchy: x> a 1517-04-01 a 1620-11-21 b 1517-04-01 b 1620-11-21 c 1517-04-01 c 1620-11-21 <<U1> <datetime64[D]> >>> ih.iloc_searchsorted(('b', np.datetime64('1620-11-21'))) 3
- IndexHierarchy.index_at_depth(depth_level=0)[source]
Return an index, or a tuple of indices for the
depth_level
specified.- Parameters:
depth_level – a single depth level, or iterable depth of depth levels.
>>> ih = sf.IndexHierarchy.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> a 1024 1517-04-01 a 2048 1789-12-31 b 0 1620-11-21 <<U1> <int64> <datetime64[D]> >>> ih.index_at_depth(0) <Index> a b <<U1> >>> ih.index_at_depth([2, 0]) (<IndexDate> 1517-04-01 1789-12-31 1620-11-21 <datetime64[D]>, <Index> a b <<U1>)
- IndexHierarchy.indexer_at_depth(depth_level=0)[source]
Return the indexers for the
depth_level
specified. Array will 2D if multiple depths are selected.- Parameters:
depth_level – a single depth level, or iterable depth of depth levels.
>>> ih = sf.IndexHierarchy.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> a 1024 1517-04-01 a 2048 1789-12-31 b 0 1620-11-21 <<U1> <int64> <datetime64[D]> >>> ih.indexer_at_depth(0) [0 0 1] >>> ih.indexer_at_depth([2, 0]) [[0 1 2] [0 0 1]]
- IndexHierarchy.intersection(*others)[source]
Perform intersection with one or many Index, container, or NumPy array. Identical comparisons retain order.
>>> ih1 = sf.IndexHierarchy.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x') >>> ih1 <IndexHierarchy: x> a 1024 True a 2048 True a 2048 False <<U1> <int64> <bool> >>> ih2 = sf.IndexHierarchy.from_labels((('a', 1024, True), ('b', 1024, True)), name='y') >>> ih2 <IndexHierarchy: y> a 1024 True b 1024 True <<U1> <int64> <bool> >>> ih1.intersection(ih2) <IndexHierarchy> a 1024 True <<U1> <int64> <bool>
- IndexHierarchy.isfalsy()
Return a same-shaped, Boolean
ndarray
indicating which values are falsy.>>> ih = sf.IndexHierarchy.from_labels((('b', np.nan, True), ('', 4096, None), ('c', 0, False)), name='y') >>> ih.isfalsy() [[False True False] [ True False True] [False True True]]
- IndexHierarchy.isin(other)[source]
Return a Boolean array showing True where one or more of the passed in iterable of labels is found in the index.
>>> ih = sf.IndexHierarchy.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate)) >>> ih <IndexHierarchy: x> a 1517-04-01 a 1620-11-21 b 1517-04-01 b 1620-11-21 c 1517-04-01 c 1620-11-21 <<U1> <datetime64[D]> >>> ih.isin((('c', np.datetime64('1517-04-01')), ('a', np.datetime64('1620-11-21')))) [False True False False True False]
- IndexHierarchy.isna()
Return a same-shaped, Boolean
ndarray
indicating which values are NaN or None.>>> ih = sf.IndexHierarchy.from_labels((('b', np.nan, True), ('', 4096, None), ('c', 0, False)), name='y') >>> ih.isna() [[False True False] [False False True] [False False False]]
- IndexHierarchy.label_widths_at_depth(depth_level=0)[source]
A generator of pairs, where each pair is the label and the contiguous count of that label found at the depth specified by
depth_level
.- Parameters:
depth_level – a depth level, starting from zero.
>>> ih = sf.IndexHierarchy.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False), ('b', 1024, True)), name='x') >>> ih <IndexHierarchy: x> a 1024 True a 2048 True a 2048 False b 1024 True <<U1> <int64> <bool> >>> tuple(ih.label_widths_at_depth(0)) (('a', 3), ('b', 1)) >>> tuple(ih.label_widths_at_depth(1)) ((1024, 1), (2048, 2), (1024, 1)) >>> tuple(ih.label_widths_at_depth(2)) ((True, 2), (False, 1), (True, 1))
- IndexHierarchy.level_add(level, *, index_constructor=None)[source]
Return an IndexHierarchy with a new root (outer) level added.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024), (1, 2048), (np.nan, np.nan)), name=('x', 'y')) >>> ih <IndexHierarchy: ('x', 'y')> 0.0 1024.0 1.0 2048.0 nan nan <float64> <float64> >>> ih.level_add('A') <IndexHierarchy: ('x', 'y')> A 0.0 1024.0 A 1.0 2048.0 A nan nan <<U1> <float64> <float64>
- IndexHierarchy.level_drop(count=1)[source]
Return an IndexHierarchy with one or more leaf levels removed.
- Parameters:
count – A positive value is the number of depths to remove from the root (outer) side of the hierarchy; a negative value is the number of depths to remove from the leaf (inner) side of the hierarchy.
>>> ih = sf.IndexHierarchy.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> a 1024 1517-04-01 a 2048 1789-12-31 b 0 1620-11-21 <<U1> <int64> <datetime64[D]> >>> ih.level_drop() <IndexHierarchy: ('y', 'z')> 1024 1517-04-01 2048 1789-12-31 0 1620-11-21 <int64> <datetime64[D]>
- IndexHierarchy.loc_searchsorted(values, *, side_left=True, fill_value=nan)[source]
Given a sorted
Series
, return the loc (label) position(s) at which insertion invalues
would retain sort order.- Parameters:
values – a single value, or iterable of values.
side_left – If True, the index of the first suitable location found is given, else return the last such index. If matching an existing value, side_left==True will return that position, side_left==Right will return the next position (or the length).
fill_value – A value to be used to fill the label beyond the last label.
>>> ih = sf.IndexHierarchy.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate)) >>> ih <IndexHierarchy: x> a 1517-04-01 a 1620-11-21 b 1517-04-01 b 1620-11-21 c 1517-04-01 c 1620-11-21 <<U1> <datetime64[D]> >>> ih.loc_searchsorted(('b', np.datetime64('1620-11-21'))) ('b', numpy.datetime64('1620-11-21'))
- IndexHierarchy.loc_to_iloc(key)[source]
Given a label (loc) style key (either a label, a list of labels, a slice, an HLoc object, or a Boolean selection), return the index position (iloc) style key. Keys that are not found will raise a KeyError or a sf.LocInvalid error.
- Parameters:
key – a label key.
>>> ih = sf.IndexHierarchy.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False), ('b', 1024, True)), name='x') >>> ih <IndexHierarchy: x> a 1024 True a 2048 True a 2048 False b 1024 True <<U1> <int64> <bool> >>> ih.loc_to_iloc(('b', 1024, True)) 3 >>> ih.loc_to_iloc([('a', 1024, True), ('b', 1024, True)]) [0, 3] >>> ih.loc_to_iloc(slice(('a', 2048, False), None)) slice(2, None, None)
- IndexHierarchy.max(axis=0, skipna=True, out=None)
Return the maximum along the specified axis.
- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.max() [ 1 1024 32]
- IndexHierarchy.mean(axis=0, skipna=True, out=None)
Return the mean along the specified axis.
- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.mean() NotImplementedError('<function mean at 0x7f9bd8bdade0> for IndexHierarchy is not defined; convert to `Frame`.')
- IndexHierarchy.median(axis=0, skipna=True, out=None)
Return the median along the specified axis.
- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.median() NotImplementedError('<function median at 0x7f9bb01af060> for IndexHierarchy is not defined; convert to `Frame`.')
- IndexHierarchy.min(axis=0, skipna=True, out=None)
Return the minimum along the specified axis.
- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.min() [ 0 1024 32]
- IndexHierarchy.notfalsy()
Return a same-shaped, Boolean
ndarray
indicating which values are falsy.>>> ih = sf.IndexHierarchy.from_labels((('b', np.nan, True), ('', 4096, None), ('c', 0, False)), name='y') >>> ih.notfalsy() [[ True False True] [False True False] [ True False False]]
- IndexHierarchy.notna()
Return a same-shaped, Boolean
ndarray
indicating which values are NaN or None.>>> ih = sf.IndexHierarchy.from_labels((('b', np.nan, True), ('', 4096, None), ('c', 0, False)), name='y') >>> ih.notna() [[ True False True] [ True True False] [ True True True]]
- IndexHierarchy.prod(axis=0, skipna=True, allna=1, out=None)
Return the product along the specified axis.
- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.prod() NotImplementedError('<function prod at 0x7f9bd8bda700> for IndexHierarchy is not defined; convert to `Frame`.')
- IndexHierarchy.rehierarch(depth_map, *, index_constructors=None)[source]
Return a new
IndexHierarchy
that conforms to the new depth assignments given be depth_map.>>> ih = sf.IndexHierarchy.from_labels((('b', 1024, True), ('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x') >>> ih <IndexHierarchy: x> b 1024 True a 1024 True a 2048 True a 2048 False <<U1> <int64> <bool> >>> ih.rehierarch([2, 0, 1]) <IndexHierarchy> True b 1024 True a 1024 True a 2048 False a 2048 <bool> <<U1> <int64>
- IndexHierarchy.relabel(mapper)[source]
Return a new IndexHierarchy with labels replaced by the callable or mapping; order will be retained. If a mapping is used, the mapping should map tuple representation of labels, and need not map all origin keys.
>>> ih = sf.IndexHierarchy.from_labels((('b', 1024, True), ('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x') >>> ih <IndexHierarchy: x> b 1024 True a 1024 True a 2048 True a 2048 False <<U1> <int64> <bool> >>> ih.relabel(lambda l: (l[0], l[1], str(l[2])[0])) <IndexHierarchy: x> b 1024 T a 1024 T a 2048 T a 2048 F <<U1> <int64> <<U1>
- IndexHierarchy.relabel_at_depth(mapper, depth_level=0)[source]
Return a new
IndexHierarchy
after applying mapper to a level or each individual level specified by depth_level.- mapper can be a callable, mapping, or iterable.
If a callable, it must accept a single hashable, and return a single hashable.
If a mapping, it must map a single hashable to a single hashable.
If a iterable, it must be the same length as self.
This call:
>>> index.relabel_at_depth(mapper, depth_level=[0, 1, 2])
is equivalent to:
>>> for level in [0, 1, 2]: >>> index = index.relabel_at_depth(mapper, depth_level=level)
albeit more efficient.
>>> ih = sf.IndexHierarchy.from_labels((('b', 1024, True), ('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x') >>> ih <IndexHierarchy: x> b 1024 True a 1024 True a 2048 True a 2048 False <<U1> <int64> <bool> >>> ih.relabel_at_depth(lambda l: str(l)[0], depth_level=[1, 2]) <IndexHierarchy: x> b 1 T a 1 T a 2 T a 2 F <<U1> <<U1> <<U1>
- IndexHierarchy.rename(name)[source]
Return a new IndexHierarchy with an updated name attribute.
>>> ih = sf.IndexHierarchy.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False), ('b', 1024, True)), name='x') >>> ih <IndexHierarchy: x> a 1024 True a 2048 True a 2048 False b 1024 True <<U1> <int64> <bool> >>> ih.rename('y') <IndexHierarchy: y> a 1024 True a 2048 True a 2048 False b 1024 True <<U1> <int64> <bool>
- IndexHierarchy.roll(shift)[source]
Return an
IndexHierarchy
with values rotated forward and wrapped around (with a positive shift) or backward and wrapped around (with a negative shift).>>> ih = sf.IndexHierarchy.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate)) >>> ih <IndexHierarchy: x> a 1517-04-01 a 1620-11-21 b 1517-04-01 b 1620-11-21 c 1517-04-01 c 1620-11-21 <<U1> <datetime64[D]> >>> ih.roll(2) <IndexHierarchy: x> c 1517-04-01 c 1620-11-21 a 1517-04-01 a 1620-11-21 b 1517-04-01 b 1620-11-21 <<U1> <datetime64[D]>
- IndexHierarchy.sample(count=1, *, seed=None)
Randomly (optionally made deterministic with a fixed seed) extract items from the container to return a subset of the container.
- Parameters:
select. (Number of elements to) –
selection. (Initial state of random) –
>>> ih = sf.IndexHierarchy.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate)) >>> ih <IndexHierarchy: x> a 1517-04-01 a 1620-11-21 b 1517-04-01 b 1620-11-21 c 1517-04-01 c 1620-11-21 <<U1> <datetime64[D]> >>> ih.sample(2, seed=0) <IndexHierarchy: x> b 1517-04-01 c 1620-11-21 <<U1> <datetime64[D]>
- IndexHierarchy.sort(*, ascending=True, kind='mergesort', key=None)[source]
Return a new Index with the labels sorted.
- Parameters:
ascendings – Boolean, or iterable of Booleans; if
True
, the lowest ranks correspond to the lowest values; if an iterable, apply per column or row. The default isTrue
.kind – Name of the sort algorithm as passed to NumPy.
key – A function that is used to pre-process the selected columns or rows and derive new values to sort by.
>>> ih = sf.IndexHierarchy.from_labels((('b', 1024, True), ('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x') >>> ih <IndexHierarchy: x> b 1024 True a 1024 True a 2048 True a 2048 False <<U1> <int64> <bool> >>> ih.sort() <IndexHierarchy: x> a 1024 True a 2048 False a 2048 True b 1024 True <<U1> <int64> <bool> >>> ih.sort(ascending=False) <IndexHierarchy: x> b 1024 True a 2048 True a 2048 False a 1024 True <<U1> <int64> <bool>
- IndexHierarchy.std(axis=0, skipna=True, ddof=0, out=None)
Return the standard deviaton along the specified axis.
- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.std() NotImplementedError('functools.partial(<function std at 0x7f9bd8bd2af0>, ddof=0) for IndexHierarchy is not defined; convert to `Frame`.')
- IndexHierarchy.sum(axis=0, skipna=True, allna=0, out=None)
Sum values along the specified axis.
- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.sum() NotImplementedError('<function sum at 0x7f9bd8bd9d00> for IndexHierarchy is not defined; convert to `Frame`.')
- IndexHierarchy.tail(count=5)
Return a
Index
consisting only of the bottom elements as specified bycount
.- Parameters:
count – Number of elements to be returned from the bottom of the
Index
>>> ih = sf.IndexHierarchy.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate)) >>> ih <IndexHierarchy: x> a 1517-04-01 a 1620-11-21 b 1517-04-01 b 1620-11-21 c 1517-04-01 c 1620-11-21 <<U1> <datetime64[D]> >>> ih.tail(2) <IndexHierarchy: x> c 1517-04-01 c 1620-11-21 <<U1> <datetime64[D]>
- IndexHierarchy.union(*others)[source]
Perform union with another Index, container, or NumPy array. Identical comparisons retain order.
>>> ih1 = sf.IndexHierarchy.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x') >>> ih1 <IndexHierarchy: x> a 1024 True a 2048 True a 2048 False <<U1> <int64> <bool> >>> ih2 = sf.IndexHierarchy.from_labels((('a', 1024, True), ('b', 1024, True)), name='y') >>> ih2 <IndexHierarchy: y> a 1024 True b 1024 True <<U1> <int64> <bool> >>> ih1.union(ih2) <IndexHierarchy> a 2048 False a 1024 True b 1024 True a 2048 True <<U1> <int64> <bool>
- IndexHierarchy.unique(depth_level=0, order_by_occurrence=False)[source]
Return a NumPy array of unique values.
- Parameters:
depth_level – Specify a single depth or multiple depths in an iterable.
order_by_occurrence – if True, values are ordered by when they first appear
- Returns:
numpy.ndarray
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024), (1, 2048), (np.nan, np.nan)), name=('x', 'y')) >>> ih <IndexHierarchy: ('x', 'y')> 0.0 1024.0 1.0 2048.0 nan nan <float64> <float64> >>> ih.unique() [ 0. 1. nan]
- IndexHierarchy.values_at_depth(depth_level=0)[source]
Return an NP array for the
depth_level
specified.- Parameters:
depth_level – a single depth level, or iterable depth of depth levels.
>>> ih = sf.IndexHierarchy.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> a 1024 1517-04-01 a 2048 1789-12-31 b 0 1620-11-21 <<U1> <int64> <datetime64[D]> >>> ih.values_at_depth(0) ['a' 'a' 'b'] >>> ih.values_at_depth(2) ['1517-04-01' '1789-12-31' '1620-11-21']
- IndexHierarchy.var(axis=0, skipna=True, ddof=0, out=None)
Return the variance along the specified axis.
- Parameters:
axis – Axis, defaulting to axis 0.
skipna – Skip missing (NaN) values, defaulting to True.
>>> ih = sf.IndexHierarchy.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z')) >>> ih <IndexHierarchy: ('x', 'y', 'z')> 0 1024 32 1 -2048 32 1 1024 32 <int64> <int64> <int64> >>> ih.var() NotImplementedError('functools.partial(<function var at 0x7f9bd8bd2cb0>, ddof=0) for IndexHierarchy is not defined; convert to `Frame`.')
IndexHierarchy: Constructor | Exporter | Attribute | Method | Dictionary-Like | Display | Selector | Iterator | Operator Binary | Operator Unary | Accessor Values | Accessor Datetime | Accessor String | Accessor Transpose | Accessor Regular Expression | Accessor Hashlib | Accessor Type Clinic