How can I iterate through multiple dataframes to select a column in each in python?
<p>For my project I'm reading in a csv file with data from every State in the US. My function converts each of these into a separate Dataframe as I need to perform operations on each State's information.</p>

<pre><code>def RanktoDF(csvFile):
    df = pd.read_csv(csvFile)
    df = df[pd.notnull(df['Index'])] # drop all null values
    df = df[df.Index != 'Index'] #Drop all extra headers
    df= df.set_index('State') #Set State as index
    return df
</code></pre>

<p>I apply this function to every one of my files and return the df with a name from my array varNames</p>

<pre><code>for name , s in zip (glob.glob('*.csv'), varNames):
    vars()["Crime" + s] = RanktoDF(name)
</code></pre>

<p>All of that works perfectly.
My problem is that I also want to create a Dataframe thats made up of one column from each of those State Dataframes.</p>

<p>I have tried iterating through a list of my dataframes and selecting the column (population) i want to append it to a new Dataframe:</p>

<p><a href="http://i.stack.imgur.com/xD2ec.png" rel="nofollow">dfList</a> </p>

<pre><code>dfNewIndex = pd.DataFrame(index=CrimeRank_1980_df.index) # Create new DF with Index


for name in dfList:  #dfList is my list of dataframes. See image
    newIndex = name['Population']
    dfNewIndex.append(newIndex)

    #dfNewIndex = pd.concat([dfNewIndex, dfList[name['Population']], axis=1)
</code></pre>

<p>My error is always the same which tells me that name is viewed as a string rather than an actual Dataframe</p>

<pre><code>TypeError                                 Traceback (most recent call last)
&lt;ipython-input-30-5aa85b0174df&gt; in &lt;module&gt;()
      3 
      4 for name in dfList:
----&gt; 5     newIndex = name['Index']
      6     dfNewIndex.append(newIndex)
      7 #     dfNewIndex = pd.concat([dfNewIndex, dfList[name['Population']], axis=1)

TypeError: string indices must be integers
</code></pre>

<p>I understand that my list is a list of Strings rather than variables/dataframes so my question is how can i correct my code to be able to do what i want or is there an easier way of doing this?</p>

<p>Any solutions I've looked up have given answers where the dataframes are explicitly typed in order to be concatenated but I have 50 so its a little unfeasible. Any help would be appreciated.</p>