0
0
Pandasdata~15 mins

Selecting multiple columns in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Selecting multiple columns
📖 Scenario: You work in a small bookstore. You have a list of books with details like title, author, year, and price. You want to look at only the title and price columns to decide which books to promote.
🎯 Goal: Learn how to select multiple columns from a pandas DataFrame to focus on specific information.
📋 What You'll Learn
Create a pandas DataFrame with book data
Create a list of column names to select
Select multiple columns from the DataFrame using the list
Print the selected columns
💡 Why This Matters
🌍 Real World
Selecting specific columns helps you focus on important data, like prices and titles, when working with large datasets.
💼 Career
Data analysts and scientists often select multiple columns to prepare data for reports, visualizations, or further analysis.
Progress0 / 4 steps
1
Create the book DataFrame
Import pandas as pd and create a DataFrame called books with these exact columns and rows:
'Title': 'The Alchemist', '1984', 'Python 101'
'Author': 'Paulo Coelho', 'George Orwell', 'Michael Driscoll'
'Year': 1988, 1949, 2019
'Price': 10.99, 8.99, 29.99
Pandas
Need a hint?

Use pd.DataFrame with a dictionary where keys are column names and values are lists of column values.

2
Create a list of columns to select
Create a list called cols_to_select containing the exact strings 'Title' and 'Price'.
Pandas
Need a hint?

Use square brackets to create a list with the two column names as strings.

3
Select the columns from the DataFrame
Create a new DataFrame called selected_books by selecting the columns in cols_to_select from the books DataFrame.
Pandas
Need a hint?

Use books[cols_to_select] to select multiple columns by passing the list inside square brackets.

4
Print the selected columns
Print the selected_books DataFrame to see only the Title and Price columns.
Pandas
Need a hint?

Use print(selected_books) to display the DataFrame with only the selected columns.