Week 1 hw compute_breed_proportions(df):

Hello,

I’m completely lost on how to loop through the breeds. specifically on groups. I’m not entirely sure how to do that
groups = df.groupby(‘breed’)
seems to be giving me pandas.core.groupby.generic.DataFrameGroupBy object at 0x7fc65e182260> which when i use to loop through with the following code :
for breed, group in groups:

df_breed = df[df[“breed”] == breed]
prob_class = df_breed[‘breed’]/len(df)
probs_dict = round(prob_class, 3)

i end up with thousands and thousands of lines:
Probability of each class for training split:

0 0.001
7 0.001
8 0.001
10 0.001
13 0.001

2393 0.001
2401 0.001
2402 0.001
2406 0.001
2407 0.001

what am i doing wrong?

i solved it!

it was working well i just didnt realize that i had to isolate the data I wanted into the dictionary. man what a syntax mess

Hey @Paul_Zhang,
Welcome, and we are glad that you could become a part of our community :partying_face:

I am glad that you were able to resolve the error on your own, after all, there is nothing better than that.

Cheers,
Elemento

1 Like

Probability of each class for training split:

1 0.0
2 0.0
4 0.0
5 0.0
9 0.0

2399 0.0
2400 0.0
2403 0.0
2409 0.0
2414 0.0
Name: breed, Length: 836, dtype: float64

getting this output… i dont understand what mistake i am doing