Code: Alles auswählen
import pandas as pd
def proportion_of_education():
df = pd.read_csv("assets/NISPUF17.csv", sep=",", usecols=["EDUC1"])
# print (df)
gesamt = df.apply( lambda x : True if x[0] != 0 else False, axis = 1)
gesamt_rows = len(gesamt[gesamt == True].index)
# print (gesamt_rows)
counterFunc = df.apply(
lambda x: True if x[0] == 1 else False , axis=1)
numOfRows_less = len(counterFunc[counterFunc == True].index)
counterFunc = df.apply(
lambda x: True if x[0] == 2 else False , axis=1)
numOfRows_high = len(counterFunc[counterFunc == True].index)
counterFunc = df.apply(
lambda x: True if x[0] == 3 else False , axis=1)
numOfRows_more = len(counterFunc[counterFunc == True].index)
counterFunc = df.apply(
lambda x: True if x[0] == 4 else False , axis=1)
numOfRows_college = len(counterFunc[counterFunc == True].index)
dict = {"less than high school": numOfRows_less/gesamt_rows, "high school": numOfRows_high/gesamt_rows,
"more than high school but not college": numOfRows_high/gesamt_rows, "college": numOfRows_college/gesamt_rows}
print (dict)
# your code goes here
# YOUR CODE HERE
return dict
raise NotImplementedError()
{'less than high school': 0.10202002459160373, 'high school': 0.172352011241876, 'more than high school but not college': 0.172352011241876, 'college': 0.47974705779026877}
{'less than high school': 0.10202002459160373, 'high school': 0.172352011241876, 'more than high school but not college': 0.172352011241876, 'college': 0.47974705779026877}
{'less than high school': 0.10202002459160373, 'high school': 0.172352011241876, 'more than high school but not college': 0.172352011241876, 'college': 0.47974705779026877}
{'less than high school': 0.10202002459160373, 'high school': 0.172352011241876, 'more than high school but not college': 0.172352011241876, 'college': 0.47974705779026877}
{'less than high school': 0.10202002459160373, 'high school': 0.172352011241876, 'more than high school but not college': 0.172352011241876, 'college': 0.47974705779026877}
{'less than high school': 0.10202002459160373, 'high school': 0.172352011241876, 'more than high school but not college': 0.172352011241876, 'college': 0.47974705779026877}
usw
Warum?