Tell us what’s happening:
I have got an error that there is no pandas module , how could I fix this, thanks so much
Traceback (most recent call last):
File “main.py”, line 2, in
import demographic_data_analyzer
File “/home/runner/boilerplate-demographic-data-analyzer-4/demographic_data_analyzer.py”, line 1, in
import pandas as pd
ModuleNotFoundError: No module named ‘pandas’
Your code so far
import pandas as pd
def calculate_demographic_data(print_data=True):
# Read data from file
df = pd.read_csv("adult.data.csv")
total_row = df.shape[0]
# How many of each race are represented in this dataset? This should be a Pandas series with race names as the index labels.
race_count = df["race"].value_counts()
# What is the average age of men?
average_age_men = round(df[df['sex'] == 'Male']['age'].mean(),1)
# What is the percentage of people who have a Bachelor's degree?
num_bachelor = df[df['education'] == 'Bachelors'].shape[0]
percentage_bachelors = round((100 * num_bachelor / total_row),1)
# 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?
# with and without `Bachelors`, `Masters`, or `Doctorate`
# percentage with salary >50K
high_edu = \
(df[(df['education'] == 'Bachelors') | (df['education'] == 'Master') | (df['education'] == 'Doctorate')]).shape[0]
higher_education = round((100 * high_edu / total_row),1)
high_edu_salary = (df[
(df['education'] == 'Bachelors') & (df['salary'] == '>50K') | (df['education'] == 'Master') & (
df['salary'] == '>50K') | (df['education'] == 'Doctorate') & (df['salary'] == '>50K')]).shape[0]
higher_education_rich = round((100 * high_edu_salary / high_edu),1)
without_high_edu = round((100 * (total_row - high_edu) / total_row),1)
without_high_edu_salary = (df[
(df['education'] != 'Bachelors') & (df['salary'] == '>50K') | (df['education'] != 'Master') & (
df['salary'] == '>50K') | (df['education'] != 'Doctorate') & (df['salary'] == '>50K')]).shape[0]
lower_education_rich = round((100 * without_high_edu_salary / without_high_edu),1)
# What is the minimum number of hours a person works per week (hours-per-week feature)?
min_work_hours = df['hours-per-week'].min()
# What percentage of the people who work the minimum number of hours per week have a salary of >50K?
num_min_workers = df[df['hours-per-week'] == 1].shape[0]
min_work_salary = df[(df['hours-per-week'] == 1) & df['salary'] == '>50K'].shape[0]
rich_percentage = round((100 * min_work_salary / num_min_workers),1)
# What country has the highest percentage of people that earn >50K?
country_salary50K = df[df['salary'] == '>50K']['native-country'].value_counts()
country_salary = df['native-country'].value_counts()
highest_earning_country = (country_salary50K / country_salary).idxmax()
highest_earning_country_percentage = round((country_salary50K / country_salary).max(),1)
# Identify the most popular occupation for those who earn >50K in India.
top_IN_occupation = df[(df["salary"] == ">50K") & (df["native-country"] == 'India')][
"occupation"].value_counts().idxmax()
# DO NOT MODIFY BELOW THIS LINE
if print_data:
print("Number of each race:\n", race_count)
print("Average age of men:", average_age_men)
print(f"Percentage with Bachelors degrees: {percentage_bachelors}%")
print(f"Percentage with higher education that earn >50K: {higher_education_rich}%")
print(f"Percentage without higher education that earn >50K: {lower_education_rich}%")
print(f"Min work time: {min_work_hours} hours/week")
print(f"Percentage of rich among those who work fewest hours: {rich_percentage}%")
print("Country with highest percentage of rich:", highest_earning_country)
print(f"Highest percentage of rich people in country: {highest_earning_country_percentage}%")
print("Top occupations in India:", top_IN_occupation)
return {
'race_count': race_count,
'average_age_men': average_age_men,
'percentage_bachelors': percentage_bachelors,
'higher_education_rich': higher_education_rich,
'lower_education_rich': lower_education_rich,
'min_work_hours': min_work_hours,
'rich_percentage': rich_percentage,
'highest_earning_country': highest_earning_country,
'highest_earning_country_percentage':
highest_earning_country_percentage,
'top_IN_occupation': top_IN_occupation
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
Challenge: Data Analysis with Python Projects - Demographic Data Analyzer
Link to the challenge: