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 to move multiple columns to the index, forming a hierarchical/multi-index. Hierarchical indexes will be covered later in the chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset