Loop all data set to get the sample mean at once

I try to use the loops on 5 datasets to get the sample mean. why my codes dont work? And there is an error showing. Thank you!

Screen Link: https://app.dataquest.io/m/283/sampling/7/stratified-sampling

My Code:

groupdata=[stratum_G,stratum_F,stratum_C,stratum_GF,stratum_FC]

points_per_position={}
for i in groupdata:
    sample=groupdata['Pts_per_game'].sample(10,random_state=0)
    points_per_position[i]=sample.mean()

What actually happened:

list indices must be integers, not str
1 Like

Inside for loop you are using groupdata that is list of dataframes. I think you suppose to use i here.
like

sample = i['Pts_per_game'].sample(10, random_state=0)

Now it makes more sense to me. thank you!!

1 Like