Key error: '3' When extracting data from Pandas DataFrame
<p>My code plan is as follows: </p>

<p>1) find csv files in folder using glob and create a list of files</p>

<p>2) covert each csv file into dataframe</p>

<p>3) extract data from a column location and convert into a separate dataframe</p>

<p>4) append the new data into a separate summary csv file </p>

<p>code is as follows: </p>

<pre><code>Result = []

def result(filepath):
    files = glob.glob(filepath)
    print files
    dataframes = [pd.DataFrame.from_csv(f, index_col=None) for f in files]
    new_dfb = pd.DataFrame()

    for i, df in enumerate(dataframes):
        colname = 'Run {}'.format(i+1)
        selected_data = df['3'].ix[0:4] 
        new_dfb[colname] = selected_data
    Result.append(new_dfb)
    folder = r"C:/Users/Joey/Desktop/tcd/summary.csv"
    new_dfb.to_csv(folder)

result("C:/Users/Joey/Desktop/tcd/*.csv")

print Result
</code></pre>

<p>The code error is shown below. The issue seems to be with line 36 .. which corresponds to the  <code>selected_data = df['3'].ix[0:4]</code>. </p>

<p><a href="https://i.stack.imgur.com/FUJwS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FUJwS.png" alt="enter image description here"></a></p>

<p>I show one of my csv files below: </p>

<p><a href="https://i.stack.imgur.com/wnNwm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wnNwm.png" alt="enter image description here"></a></p>

<p>I'm not sure what the problem is with the dataframe constructor? </p>