What does the frame variable signify in this code?
for group, frame in df.groupby('STNAME'):
avg = np.average(frame['CENSUS2010POP'])
print('Counties in state ' + group + ' have an average population of ' + str(avg))
What does the frame variable signify in this code?
for group, frame in df.groupby('STNAME'):
avg = np.average(frame['CENSUS2010POP'])
print('Counties in state ' + group + ' have an average population of ' + str(avg))
frame here is sub_group, since you groupby STNAME
So the for loop here is equal to
for x in df['STNAME'].unique():
frame=df[df.STNAME==x]
avg = np.average(frame['CENSUS2010POP'])