0
0
Data Analysis Pythondata~15 mins

Selecting columns in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Selecting columns
📖 Scenario: You work in a small shop that keeps track of sales data in a table. You want to look at only some parts of the data to understand it better.
🎯 Goal: You will create a table of sales data and then select only the columns for Product and Price to see just those details.
📋 What You'll Learn
Create a pandas DataFrame with specific sales data
Create a list of column names to select
Select only the specified columns from the DataFrame
Print the selected columns DataFrame
💡 Why This Matters
🌍 Real World
Selecting specific columns from data tables is common when you want to focus on certain details, like product names and prices in sales data.
💼 Career
Data analysts and scientists often select columns to prepare data for reports, visualizations, or further analysis.
Progress0 / 4 steps
1
Create the sales data table
Create a pandas DataFrame called sales_data with these exact columns and rows:
Product: 'Apple', 'Banana', 'Carrot'
Price: 0.5, 0.3, 0.2
Quantity: 10, 20, 15
Data Analysis Python
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 columns_to_select that contains the exact column names 'Product' and 'Price'.
Data Analysis Python
Need a hint?

Make a list with the two column names as strings.

3
Select the columns from the DataFrame
Create a new DataFrame called selected_data by selecting only the columns in columns_to_select from sales_data.
Data Analysis Python
Need a hint?

Use bracket notation with the list of columns to select from the DataFrame.

4
Print the selected columns
Print the selected_data DataFrame to see only the Product and Price columns.
Data Analysis Python
Need a hint?

Use print(selected_data) to show the selected columns.