pandas.DataFrame.reindex
pandas 3.1.1 · DataFrame · method
Conform to supplied labels and fill positions where those labels did not previously exist.
Call syntax
DataFrame.reindex(…) Full signature
DataFrame.reindex(
labels=None,
*,
index=None,
columns=None,
axis=None,
method=None,
copy=…,
level=None,
fill_value=nan,
limit=None,
tolerance=None,
)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
labels |
Optional Positional or keyword Default None |
array-like Provide the labels used for selecting rows, renaming entries, or naming bins. |
index |
Optional Keyword only Default None |
array-like Supply row labels or control how existing row labels are used. |
columns |
Optional Keyword only Default None |
array-like Supply column labels or control how columns are handled. |
axis |
Optional Keyword only Default None |
int or str Choose which axis the operation acts on. The accepted axis labels depend on the receiver. |
method |
Optional Keyword only Default None |
{None, 'backfill'/'bfill', 'pad'/'ffill', 'nearest'} Choose the algorithm used to calculate, align, or fill the result. |
copy |
Optional Keyword only |
bool Control whether data is copied where the API supports that choice. |
level |
Optional Keyword only Default None |
int or name Choose an index level by name or integer position. |
fill_value |
Optional Keyword only Default nan |
scalar Supply a value to use in place of a missing position. |
limit |
Optional Keyword only Default None |
int Set a maximum number of items affected by the operation. |
tolerance |
Optional Keyword only Default None |
Set the maximum acceptable distance for an inexact match. |
Returns
DataFrame