O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Moving data to and from the index

A DataFrame object can have its index reset by using the .reset_index(). A common use of this is for moving the contents of a DataFrame object's index into one or more columns.

The following code moves the symbols in the index of sp500 into a column and replaces the index with a default integer index.

A column of data can be moved to the index of a DataFrame object using the .set_index() method and by specifying the column to be moved. The following code moves the Sector column to the index.

It is possible ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required