[Solved] how can I loop to get the list named vlist?


Check this out. List Comprehension

import numpy as np
import pandas as pd
df = pd.read_csv('census.csv')
data = ['SUMLEV','STNAME', 'CTYNAME', 'CENSUS2010POP']
df=df[data]
adf = df[df['SUMLEV']==50]
adf.set_index('STNAME', inplace=True)
states = np.array(adf.index.unique())


vlist=[adf.loc[states[i]]['CENSUS2010POP'].sort_values(ascending =False).head(3).sum() for i in range(0,7)]

3

solved how can I loop to get the list named vlist?