2016-01-19

Python Pandas reindex and new index

The answer comes from stackoverflow.com:

So if you have a DataFrame with index [0, 1, 2], then doing a reindex([2, 1, 0]) will return the rows in reverse order. Doing something like reindex([8, 9, 10]) does not make a new index for the rows; rather, it will return a DataFrame with NaN values, since there are no rows with indices 8, 9, or 10.

To generate new index for existing rows try this:

df.index = range(len(df))