Detail: Index: Method

Overview: Index: Method

Index.__array__(dtype=None)

Support the __array__ interface, returning an array of values.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.__array__()
[1024 2048 4096]
Index.__array_ufunc__(ufunc, method, *args, **kwargs)

Support for NumPy elements or arrays on the left hand of binary operators.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> np.array((0, 1, 0)) * ix
[   0 2048    0]
Index.__bool__()

Raises ValueError to prohibit ambiguous use of truthy evaluation.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> bool(ix)
ErrorNotTruthy('The truth value of a container is ambiguous. For a truthy indicator of non-empty status, use the `size` attribute.')
Index.__copy__()[source]

Return shallow copy of this Index.

>>> import copy
>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> copy.copy(ix)
<Index: x>
a
b
c
d
e
<<U1>
Index.__deepcopy__(memo)[source]
>>> import copy
>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> copy.deepcopy(ix)
<Index: x>
a
b
c
d
e
<<U1>
Index.__len__()[source]
>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> len(ix)
5
Index.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.

>>> ix = sf.Index((0, 1024, -2048, 4096))
>>> ix
<Index>
0
1024
-2048
4096
<int64>
>>> ix.all()
False
Index.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.

>>> ix = sf.Index((0, 1024, -2048, 4096))
>>> ix
<Index>
0
1024
-2048
4096
<int64>
>>> ix.any()
True
Index.astype(dtype)[source]

Return an Index with type determined by dtype argument. If a datetime64 dtype is provided, the appropriate Index subclass will be returned. Note that for Index, this is a simple function, whereas for IndexHierarchy, this is an interface exposing both a callable and a getitem interface.

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.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.astype(float)
<Index: y>
1024.0
2048.0
4096.0
<float64>
Index.copy()[source]

Return shallow copy of this Index.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.copy()
<Index: y>
1024
2048
4096
<int64>
Index.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.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.cumprod()
[      1024    2097152 8589934592]
Index.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.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.cumsum()
[1024 3072 7168]
Index.difference(*others)

Perform difference with another Index, container, or NumPy array. Retains order.

>>> ix1 = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix1
<Index: x>
a
b
c
d
e
<<U1>
>>> ix2 = sf.Index(('c', 'd', 'e', 'f'), name='y')
>>> ix2
<Index: y>
c
d
e
f
<<U1>
>>> ix1.difference(ix2)
<Index>
a
b
<<U1>
Index.dropfalsy()[source]

Return a new Index after removing values of NaN or None.

>>> ix = sf.Index(('', 'b', 'c', 'd'))
>>> ix
<Index>

b
c
d
<<U1>
>>> ix.dropfalsy()
<Index>
b
c
d
<<U1>
Index.dropna()[source]

Return a new Index after removing values of NaN or None.

>>> ix = sf.Index((None, 'A', 1024, True), name='x')
>>> ix
<Index: x>
None
A
1024
True
<object>
>>> ix.dropna()
<Index: x>
A
1024
True
<object>
Index.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.

>>> ix1 = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix1
<Index: x>
a
b
c
d
e
<<U1>
>>> ix2 = sf.Index((1024, 2048, 4096), name='y')
>>> ix2
<Index: y>
1024
2048
4096
<int64>
>>> ix1.equals(ix2)
False
Index.fillfalsy(value)[source]

Return an Index with replacing falsy values with the supplied value.

Parameters:

value – Value to be used to replace missing values (NaN or None).

>>> ix = sf.Index(('', 'b', 'c', 'd'))
>>> ix
<Index>

b
c
d
<<U1>
>>> ix.fillfalsy('A')
<Index>
A
b
c
d
<<U1>
Index.fillna(value)[source]

Return an Index with replacing null (NaN or None) with the supplied value.

Parameters:

value – Value to be used to replace missing values (NaN or None).

>>> ix = sf.Index((None, 'A', 1024, True), name='x')
>>> ix
<Index: x>
None
A
1024
True
<object>
>>> ix.fillna(0)
<Index: x>
0
A
1024
True
<object>
Index.head(count=5)

Return a Index consisting only of the top elements as specified by count.

Parameters:

count – Number of elements to be returned from the top of the Index

>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> ix.head(2)
<Index: x>
a
b
<<U1>
Index.iloc_searchsorted(values, *, side_left=True)[source]

Given a sorted Series, return the iloc (integer) position(s) at which insertion in values 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).

>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> ix.iloc_searchsorted('c')
2
Index.intersection(*others)

Perform intersection with one or many Index, container, or NumPy array. Identical comparisons retain order.

>>> ix1 = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix1
<Index: x>
a
b
c
d
e
<<U1>
>>> ix2 = sf.Index(('c', 'd', 'e', 'f'), name='y')
>>> ix2
<Index: y>
c
d
e
f
<<U1>
>>> ix1.intersection(ix2)
<Index>
c
d
e
<<U1>
Index.isfalsy()

Return a same-shaped, Boolean ndarray indicating which values are falsy.

>>> ix = sf.Index(('a', '', None, 0, np.nan, 'b'))
>>> ix.isfalsy()
[False  True  True  True  True False]
Index.isin(other)[source]

Return a Boolean array showing True where a label is found in other. If other is a multidimensional array, it is flattened.

>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> ix.isin(('a', 'e'))
[ True False False False  True]
Index.isna()

Return a same-shaped, Boolean ndarray indicating which values are NaN or None.

>>> ix = sf.Index(('a', '', None, 0, np.nan, 'b'))
>>> ix.isna()
[False False  True False  True False]
Index.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.

>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> tuple(ix.label_widths_at_depth(0))
(('a', 1), ('b', 1), ('c', 1), ('d', 1), ('e', 1))
Index.level_add(level, *, index_constructor=None)[source]

Return an IndexHierarchy with an added root level.

Parameters:
  • level – A hashable to used as the new root.

  • *

  • index_constructor

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.level_add('A')
<IndexHierarchy: y>
A                   1024
A                   2048
A                   4096
<<U1>               <int64>
Index.loc_searchsorted(values, *, side_left=True, fill_value=nan)[source]

Given a sorted Series, return the loc (label) position(s) at which insertion in values 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.

>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> ix.loc_searchsorted('c')
c
Index.loc_to_iloc(key)[source]

Given a label (loc) style key (either a label, a list of labels, a slice, 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.

>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> ix.loc_to_iloc('d')
3
>>> ix.loc_to_iloc(['a', 'e'])
[0 4]
>>> ix.loc_to_iloc(slice('c', None))
slice(2, None, None)
Index.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.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.max()
4096
Index.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.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.mean()
2389.3333333333335
Index.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.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.median()
2048.0
Index.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.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.min()
1024
Index.notfalsy()

Return a same-shaped, Boolean ndarray indicating which values are falsy.

>>> ix = sf.Index(('a', '', None, 0, np.nan, 'b'))
>>> ix.notfalsy()
[ True False False False False  True]
Index.notna()

Return a same-shaped, Boolean ndarray indicating which values are NaN or None.

>>> ix = sf.Index(('a', '', None, 0, np.nan, 'b'))
>>> ix.notna()
[ True  True False  True False  True]
Index.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.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.prod()
8589934592
Index.relabel(mapper)[source]

Return a new Index with labels replaced by the callable or mapping; order will be retained. If a mapping is used, the mapping need not map all origin keys.

>>> ix = sf.Index(('a', 'b', 'c'), name='x')
>>> ix
<Index: x>
a
b
c
<<U1>
>>> ix.relabel(dict(a='x', c='y'))
<Index: x>
x
b
y
<<U1>
>>> ix.relabel(lambda l: l.upper() if l != 'b' else l)
<Index: x>
A
b
C
<<U1>
Index.rename(name)[source]

Return a new Frame with an updated name attribute.

>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> ix.rename('y')
<Index: y>
a
b
c
d
e
<<U1>
Index.roll(shift)[source]

Return an Index with values rotated forward and wrapped around (with a postive shift) or backward and wrapped around (with a negative shift).

>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> ix.roll(2)
<Index: x>
d
e
a
b
c
<<U1>
Index.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) –

>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> ix.sample(2, seed=0)
<Index: x>
a
c
<<U1>
Index.sort(ascending=True, kind='mergesort', key=None)[source]

Return a new Index with the labels sorted.

Parameters:
  • ascending – If True, sort in ascending order; if False, sort in descending order.

  • 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.

>>> ix = sf.Index(('b', 'e', 'c', 'a', 'd'), name='x')
>>> ix
<Index: x>
b
e
c
a
d
<<U1>
>>> ix.sort()
<Index: x>
a
b
c
d
e
<<U1>
>>> ix.sort(ascending=False)
<Index: x>
e
d
c
b
a
<<U1>
Index.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.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.std()
1277.1523880188386
Index.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.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.sum()
7168
Index.tail(count=5)

Return a Index consisting only of the bottom elements as specified by count.

Parameters:

count – Number of elements to be returned from the bottom of the Index

>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> ix.tail(2)
<Index: x>
d
e
<<U1>
Index.union(*others)

Perform union with another Index, container, or NumPy array. Identical comparisons retain order.

>>> ix1 = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix1
<Index: x>
a
b
c
d
e
<<U1>
>>> ix2 = sf.Index(('c', 'd', 'e', 'f'), name='y')
>>> ix2
<Index: y>
c
d
e
f
<<U1>
>>> ix1.union(ix2)
<Index>
a
b
c
d
e
f
<<U1>
Index.unique(depth_level=0, order_by_occurrence=False)[source]

Return a NumPy array of unique values.

Parameters:
  • depth_level – defaults to 0 for for a 1D Index.

  • order_by_occurrence – for 1D indices, this argument is a no-op. Provided for compatibility with IndexHierarchy.

Returns:

numpy.ndarray

>>> ix = sf.Index((None, 'A', 1024, True), name='x')
>>> ix
<Index: x>
None
A
1024
True
<object>
>>> ix.unique()
[None 'A' 1024 True]
Index.values_at_depth(depth_level=0)[source]

Return an NP array for the depth_level specified.

>>> ix = sf.Index(('a', 'b', 'c', 'd', 'e'), name='x')
>>> ix
<Index: x>
a
b
c
d
e
<<U1>
>>> ix.values_at_depth(0)
['a' 'b' 'c' 'd' 'e']
Index.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.

>>> ix = sf.Index((1024, 2048, 4096), name='y')
>>> ix
<Index: y>
1024
2048
4096
<int64>
>>> ix.var()
1631118.222222222

Index: Constructor | Exporter | Attribute | Method | Dictionary-Like | Display | Selector | Iterator | Operator Binary | Operator Unary | Accessor Values | Accessor Datetime | Accessor String | Accessor Regular Expression | Accessor Hashlib | Accessor Type Clinic