Populating a Pandas DataFrame frome another DataFrame based on column names
You can just use the list to select them:
In [44]:cols = ['a', 'b', 'b', 'a', 'c']df[cols]Out[44]: a b b a c0 1 4 4 1 61 3 2 2 3 42 4 1 1 4 5[3 rows x 5 columns]
So no need for a loop, once you have created your dataframe df
then using a list of column names will just index them and create the df you want.