Question: 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:
1.Load the income.csv dataset into a pandas DataFrame. The dataset contains two columns: Education and 'Income.
2.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.
3.Use conditional statements to assign each individual to the appropriate income group.
4.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 = pd.read_csv('/home/codio/workspace/csv/income.csv')
# Add your code below
Place the following code in order
# Sample data for demonstration
print(data.head())
def categorize_income_group(row):
})
'Education': ['High School', 'Bachelor\'s', 'Master\'s','PhD', 'High School', 'Bachelor\'s'], 'Income': [30000,50000,70000,90000,35000,55000]
data['Income Group']= data.apply(categorize_income_group, axis=1)
# Categorize individuals into income groups based on their education level
print("Updated DataFrame with Income Group:")
# Print the first few rows of the updated DataFrame
import pandas as pd
data = pd.DataFrame({
if row['Education'] in ['High School', 'Some College']:
return 'Low'
elif row['Education']== 'Bachelor\'s':
return 'Medium'
else:
return 'High'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!