Sorting Data with pandas using sort_values() by multiple columns
📖 Scenario: You work in a small bookstore. You have a list of books with their title, author, and year published. You want to organize this list so that books are sorted first by author name alphabetically, and then by year published from oldest to newest.
🎯 Goal: Build a pandas DataFrame with book data and sort it by author and year using sort_values() with multiple columns.
📋 What You'll Learn
Create a pandas DataFrame called
books with columns title, author, and year using the exact data provided.Create a list called
sort_columns with the column names 'author' and 'year' in that order.Use
sort_values() on the books DataFrame with the by parameter set to sort_columns.Print the sorted DataFrame.
💡 Why This Matters
🌍 Real World
Sorting data by multiple columns is common when organizing records like books, sales, or customer data to find patterns or prepare reports.
💼 Career
Data analysts and scientists often sort data by multiple criteria to clean, explore, and present data clearly.
Progress0 / 4 steps