Tell us what’s happening:
In Demographic Data Analyzer can someone explain what formula to be used in What percentage of people with advanced education (Bachelors, Masters, or Doctorate) make more than 50K?
What percentage of people without advanced education make more than 50K? I am not getting correct answer whatever I use.
TIA
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Data Analysis with Python Projects - Demographic Data Analyzer
The basic formula would be the number of people with higher education who make over 50 divided by the number of everyone with higher education, or:
higher_education_over50k / higher_education
You’ll need to format it as a percentage. I hope this helps!
If you are still running into problems please share your code.
https://github.com/Mudit5coder/Demographic-Data-Analyzer/blob/main/demographic_data_analyzer.py
Here is my code I believe I have done the same as you guide me but it is still showing error.
And with it would be very helpfull if you can guide me with the
rich_percentage and highest_earning_country_percentage
Print out the answers. What percentages are you getting? Do they make sense?
bach1 = len(df[(df["education-num"] >= 13) & (df["salary"] == ">50K")])
Num_of_people_higher_education = len(df["education-num"] >=13).sum()
You use len()
to count the number of people with higher education and over 50k salary, but then you use .sum()
to count the number of people with just higher education?
What is the difference between using len
and sum
?
I guess so like the answer I am getting is not correct .
What answer are you getting?
Traceback (most recent call last):
File “/workspace/boilerplate-demographic-data-analyzer/test_module.py”, line 27, in test_higher_education_rich
self.assertAlmostEqual(actual, expected, msg=“Expected different value for percentage with higher education that earn >50K.”)
AssertionError: 48.5 != 46.5 within 7 places (2.0 difference) : Expected different value for percentage with higher education that earn >50K.
======================================================================
FAIL: test_lower_education_rich (test_module.DemographicAnalyzerTestCase)
Traceback (most recent call last):
File “/workspace/boilerplate-demographic-data-analyzer/test_module.py”, line 32, in test_lower_education_rich
self.assertAlmostEqual(actual, expected, msg=“Expected different value for percentage without higher education that earn >50K.”)
AssertionError: 16.1 != 17.4 within 7 places (1.2999999999999972 difference) : Expected different value for percentage without higher education that earn >50K.
I believe len is to find how much values are their and sum is used add those values maybe I am not quite sure about this
Sounds right. Do you want to find how many values there are or do you want to add them all together?
that is what I am confused like I have almost tried everything but still didn’t get the correct answer.
You want to count them, not add them all together
I did try with the len method, however answer is still coming out wrong.
Can you share your updated code on github or here? It still shows sum
I didnt update it on github give me a second.
FAIL: test_higher_education_rich (test_module.DemographicAnalyzerTestCase)
Traceback (most recent call last):
File “/workspace/boilerplate-demographic-data-analyzer/test_module.py”, line 27, in test_higher_education_rich
self.assertAlmostEqual(actual, expected, msg=“Expected different value for percentage with higher education that earn >50K.”)
AssertionError: 12.0 != 46.5 within 7 places (34.5 difference) : Expected different value for percentage with higher education that earn >50K.
======================================================================
FAIL: test_lower_education_rich (test_module.DemographicAnalyzerTestCase)
Traceback (most recent call last):
File “/workspace/boilerplate-demographic-data-analyzer/test_module.py”, line 32, in test_lower_education_rich
self.assertAlmostEqual(actual, expected, msg=“Expected different value for percentage without higher education that earn >50K.”)
AssertionError: 12.1 != 17.4 within 7 places (5.299999999999999 difference) : Expected different value for percentage without higher education that earn >50K. this is the output I am getting
You are considering higher education as anything greater than or equal to education-num
13 but the question asks:
(Bachelors
, Masters
, or Doctorate
)
Are there entries with education-num >= 13
which are not in these three options?
I don’t think so like is there any thing above than doctrate!
What is the education-num
for doctorate?
There are, I wouldn’t have mentioned this if it wasn’t the case.