Get startedGet started for free

Time to read, Katniss!

It's almost time to finish working for the day. But first, you would like to do an analysis for fun. You will analyze another book dataset, this time with the Hunger Games series.

You explored the dataset books_hunger before reshaping it, but something was not right. The index of the DataFrame contains the title of the books. You know that you cannot reshape it in this format. If you do, you will lose valuable data, the title, so you'll need to make some changes before transforming the DataFrame.

The books_hunger dataset is available for you. It contains the title, and data about language, publication date, publication number, and page number of each book.

This exercise is part of the course

Reshaping Data with pandas

View Course

Exercise instructions

  • Modify the books_hunger DataFrame by resetting the index without dropping it.
  • Reshape books_hunger from wide to long format. Use the columns title and language as unique indexes. Name feature the new variable created from the columns that starts with publication and page. Those columns are separated by a blank space and end in a word.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Modify books_hunger by resetting the index without dropping it
books_hunger.____(____=____, inplace=____)

# Reshape using title and language as index, feature as new name, publication and page as prefix separated by space and ending in a word
publication_features = pd.wide_to_long(____, 
                                       ____=____, 
                                       ____=____, 
                                       ____=____, 
                                       ____=____, 
                                       ____=____)

# Print publication_features
print(publication_features)
Edit and Run Code