Sort DataFrame by Index Using sort_index()
📖 Scenario: You work in a small bookstore. You have a list of books with their prices, but the list is not sorted by the book titles. You want to organize your list alphabetically by the book titles to find books faster.
🎯 Goal: Create a pandas DataFrame with book titles as the index and prices as the values. Then, sort the DataFrame by the index (book titles) using sort_index().
📋 What You'll Learn
Create a pandas DataFrame called
books with the exact index labels: 'Python Basics', 'Data Science', 'Machine Learning', and 'Deep Learning'.The DataFrame must have a single column named
Price with the exact values: 25, 40, 55, and 60 respectively.Create a variable called
sorted_books that contains the DataFrame sorted by its index using sort_index().💡 Why This Matters
🌍 Real World
Sorting data by index helps organize information alphabetically or by date, making it easier to find and analyze data quickly.
💼 Career
Data analysts and scientists often need to sort data tables to prepare reports or perform analysis efficiently.
Progress0 / 4 steps