Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Index.reindex#

Index.reindex(target,method=None,level=None,limit=None,tolerance=None)[source]#

Create index with target’s values.

Parameters:
targetan iterable
method{None, ‘pad’/’ffill’, ‘backfill’/’bfill’, ‘nearest’}, optional
  • default: exact matches only.

  • pad / ffill: find the PREVIOUS index value if no exact match.

  • backfill / bfill: use NEXT index value if no exact match

  • nearest: use the NEAREST index value if no exact match. Tieddistances are broken by preferring the larger index value.

levelint, optional

Level of multiindex.

limitint, optional

Maximum number of consecutive labels intarget to match forinexact matches.

toleranceint or float, optional

Maximum distance between original and new labels for inexactmatches. The values of the index at the matching locations mustsatisfy the equationabs(index[indexer]-target)<=tolerance.

Tolerance may be a scalar value, which applies the same toleranceto all values, or list-like, which applies variable tolerance perelement. List-like includes list, tuple, array, Series, and must bethe same size as the index and its dtype must exactly match theindex’s type.

Returns:
new_indexpd.Index

Resulting index.

indexernp.ndarray[np.intp] or None

Indices of output values in original index.

Raises:
TypeError

Ifmethod passed along withlevel.

ValueError

If non-unique multi-index

ValueError

If non-unique index andmethod orlimit passed.

See also

Series.reindex

Conform Series to new index with optional filling logic.

DataFrame.reindex

Conform DataFrame to new index with optional filling logic.

Examples

>>>idx=pd.Index(['car','bike','train','tractor'])>>>idxIndex(['car', 'bike', 'train', 'tractor'], dtype='object')>>>idx.reindex(['car','bike'])(Index(['car', 'bike'], dtype='object'), array([0, 1]))

[8]ページ先頭

©2009-2025 Movatter.jp