Why after reindexing rows it has to be saved in a new df?

So my question is very straightforward why do we have to save the 'df .reindex() into another dataframe ‘df2’ before reindexing the columns. Does this mean the df.reindex() does not work on the original dataframe?

This is given in the topic ‘Reindexing objects’

Type your question above this line.


Hi @Ambuj_Choudha

The pandas.DataFrame.reindex method takes in a dataframe and returns a new dataframe with the updated index. In the example in the lesson, we’re saving this new dataframe in a new variable df2, but we could have also saved it in the original variable df, both would have been fine.

Hope this helped!