Question: I keep getting an error: not sure what I'm doing incorrect here: Based off of the adult.data dataset. (https://archive.ics.uci.edu/ml/machine-learning-databases/adult/): Python based problem 8.According to our
I keep getting an error: not sure what I'm doing incorrect here:
Based off of the adult.data dataset. (https://archive.ics.uci.edu/ml/machine-learning-databases/adult/): Python based problem
8.According to our data, on average who earns the most money?
Options: The young, the old, both young and old, and not sure.
Use your own judgement to classify age as listed in the options. Give a detailed explanation and interpretation of the results.
Note: my last column in the dataset is called salary and the two options are >50K and <=50K
# code and explanation here
#data.age.mean()
def age_range(age):
if age < 30:
return "Young"
elif age >= 60:
return "Old"
else:
return "Middle-aged"
data["age_range"] = data["age"].apply(age_range)
# Calculate the mean income for each age range
mean_salary = data.groupby("age_range").mean()["salary"] print(mean_salary)
Additionally for this question:
From the dataset, with the information available, which country you'd rather live? Please explain why, preferably with some data points from the dataset.
# Calculate the mean income for each country mean_salary = data.groupby("native country").mean()["salary"]
# Sort the countries by their mean income mean_salary = mean_salary.sort_values(ascending=False)
print(mean_salary)
I keep getting an error for this as well.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
