Data Analysis with Python Projects - Demographic Data Analyzer

Tell us what’s happening:

Describe your issue in detail here.
i was doing projects for the data analysis but on replit for my first project it says numpy named module not available i tried installing its package from packages but the issue didnt resolve. i tried the second project it says sh1 : use not found.
both my code are running on my jupiter notebook.

Your code so far

import pandas as pd

def calculate_demographic_data(print_data=True):
# Read data from file
df = pd.read_csv(“”)

# 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 = df[df["sex"] == "Male"]["age"].mean()

# What is the percentage of people who have a Bachelor's degree?
percentage_bachelors = (df["education"] == "Bachelors").mean() * 100

# 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`
higher_education = df[df["education"].isin(["Bachelors", "Masters", "Doctorate")]
lower_education = df[~df["education"].isin(["Bachelors", "Masters", "Doctorate"])]

# percentage with salary >50K
higher_education_rich = (higher_education["salary"] == ">50K").mean() * 100
lower_education_rich = (lower_education["salary"] == ">50K").mean() * 100

# 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"] == min_work_hours]
rich_percentage = (num_min_workers["salary"] == ">50K").mean() * 100

# What country has the highest percentage of people that earn >50K?
highest_earning_country_stats = df[df["salary"] == ">50K"]["native-country"].value_counts()
highest_earning_country = highest_earning_country_stats.idxmax()
highest_earning_country_percentage = (highest_earning_country_stats.max() / df["native-country"].value_counts().max()) * 100

# Identify the most popular occupation for those who earn >50K in India.
top_IN_occupation = df[(df["native-country"] == "India") & (df["salary"] == ">50K")]["occupation"].value_counts().idxmax()


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/ Safari/537.36 Edg/118.0.2088.69

Challenge Information:

Data Analysis with Python Projects - Demographic Data Analyzer

Please link to your replit.

Recently the poetry package could be throwing errors but then it might continue and run your code. Do you notice this happening?

Try pip install numpy at the shell command prompt.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.