pandas.DataFrame.reindex_axis¶
-
DataFrame.
reindex_axis
(labels, axis=0, method=None, level=None, copy=True, limit=None, fill_value=nan)[source]¶ Conform input object to new index.
Deprecated since version 0.21.0: Use reindex instead.
By default, places 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: - labels : array-like
New labels / index to conform to. Preferably an Index object to avoid duplicating data.
- axis : {0 or ‘index’, 1 or ‘columns’}
Indicate whether to use rows or columns.
- method : {None, ‘backfill’/’bfill’, ‘pad’/’ffill’, ‘nearest’}, optional
Method to use for filling holes in reindexed DataFrame:
- 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.
- level : int or str
Broadcast across a level, matching Index values on the passed MultiIndex level.
- copy : bool, default True
Return a new object, even if the passed indexes are the same.
- limit : int, optional
Maximum number of consecutive elements to forward or backward fill.
- fill_value : float, default NaN
Value used to fill in locations having no value in the previous index.
New in version 0.21.0: (list-like tolerance)
Returns: - DataFrame
Returns a new DataFrame object with new indices, unless the new index is equivalent to the current one and copy=False.
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.
DataFrame.reindex_like
- Change to same indices as other DataFrame.
Examples
>>> df = pd.DataFrame({'num_legs': [4, 2], 'num_wings': [0, 2]}, ... index=['dog', 'hawk']) >>> df num_legs num_wings dog 4 0 hawk 2 2 >>> df.reindex(['num_wings', 'num_legs', 'num_heads'], ... axis='columns') num_wings num_legs num_heads dog 0 4 NaN hawk 2 2 NaN