I'm new to Python. Can anybody break down the process here per line?
What does the [1:4]
do? Thank you.
def answer_six():
copy_df = census_df.copy()
copy_df = copy_df.groupby(['STNAME'])
states_pop = pd.DataFrame(columns=['pop'])
for i, c in copy_df:
states_pop.loc[i] = [c.sort_values(by='CENSUS2010POP', ascending=False)[1:4]['CENSUS2010POP'].sum()]
top3 = states_pop.nlargest(3,'pop')
return states_pop answer_six()