r/pythonhelp • u/Smart_General2218 • Jul 20 '22
HOMEWORK Incoporating len(df) value into group by()
Task 5b: Calculate percentage of people with work experience that are offered a job, the percentage of people with work experience not offered a job, the people with no work experience offered a job and the percentage of people with no work experience not offered a job.
len(df.index)
print(df.index)output
RangeIndex(start=0, stop=120, step=1) Tried to put the value of 120 into groupby but failed
df_workexp = (df.groupby('index')['status']
.value_counts(normalize=True)
.reset_index(name='perc'))
print (df_workexp)
0
Upvotes
1
u/[deleted] Jul 20 '22
Failed with what exception? What did you try putting 120 into? I don't see where you tried that and also don't understand why you want to put an index into a groupby - it'd end up giving you every row which defeats the purpose of the groupby.