Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In python: In this exercise, you will use a hypothetical dataset income.csv to analyze the relationship between education level and income. You will use conditional
In python: In this exercise, you will use a hypothetical dataset income.csv to analyze the relationship between education level and income. You will use conditional statements to categorize individuals into different income groups based on their education level.
Instructions:
Load the income.csv dataset into a pandas DataFrame. The dataset contains two columns: Education and 'Income
Create a new column in the DataFrame called Income Group that categorizes individuals into 'Low 'Medium and High income groups based on their education level.
Assume that individuals with education level High School or lower are in the Low income group.
Individuals with education level Bachelors are in the Medium income group.
Individuals with education level Masters or higher are in the High income group.
Use conditional statements to assign each individual to the appropriate income group.
Print the first few rows of the updated DataFrame to verify the income group assignments.
Starter Code:
import pandas as pd
# Load the data
data pdreadcsvhomecodioworkspacecsvincomecsv
# Add your code below
Place the following code in order
# Sample data for demonstration
printdatahead
def categorizeincomegrouprow:
'Education': High School', 'Bachelors 'MastersPhD 'High School', 'Bachelors 'Income':
dataIncome Group' data.applycategorizeincomegroup, axis
# Categorize individuals into income groups based on their education level
printUpdated DataFrame with Income Group:"
# Print the first few rows of the updated DataFrame
import pandas as pd
data pdDataFrame
if rowEducation in High School', 'Some College':
return 'Low'
elif rowEducation 'Bachelors:
return 'Medium'
else:
return 'High'
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started