Ben Chuanlong Du's Blog

It is never too late to learn.

Understand Index in pandas

Comments

  1. There are multiple ways to update the index of a DataFrame or Series. First, you can assign a new Series or Index object to the index of a DataFrame or Series. Or you can use methods such as DataFrame.set_index or DataFrame.reset_index. DataFrame.reset_index resets the index of a DataFrame/Series to an integer index starting from 0. The old index is kept by default but can be dropped using the option drop=True

Reset the Index of a pandas DataFrame

reset_index

By default reset_index returns a copy rather than modify the original data frame. You can specify inplace = True to overwrite the behavior.

Series

  1. If you drop the original index, you still have a Series. However, if you reset index of a sereis without dropping the original index, you get a data frame.