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.
Diese Übung ist Teil des Kurses
Reshaping Data with pandas
Anleitung zur Übung
- Modify the
books_hunger
DataFrame by resetting the index without dropping it. - Reshape
books_hunger
from wide to long format. Use the columnstitle
andlanguage
as unique indexes. Namefeature
the new variable created from the columns that starts withpublication
andpage
. Those columns are separated by a blank space and end in a word.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# 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)