Create dataframe from specific column
<p>I am trying to create a dataframe in Pandas from the <code>AB</code> column in my csv file. (AB is the 27th column).</p>

<p>I am using this line:</p>

<pre><code>df = pd.read_csv(filename, error_bad_lines = False, usecols = [27])
</code></pre>

<p>... which is resulting in this error:</p>

<pre><code>ValueError: Usecols do not match names.
</code></pre>

<p>I'm very new to Pandas, could someone point out what i'm doing wrong to me?</p>

<p>Here is a small demo:</p>

<p>CSV file (without header, i.e. there is NO column names):</p>

<pre><code>1,2,3,4,5,6,7,8,9,10
11,12,13,14,15,16,17,18,19,20
</code></pre>

<p>We are going to read only 8-<code>th</code> column:</p>

<pre><code>In [1]: fn = r'D:\temp\.data\1.csv'

In [2]: df = pd.read_csv(fn, header=None, usecols=[7], names=['col8'])

In [3]: df
Out[3]:
   col8
0     8
1    18
</code></pre>

<p>PS pay attention at <code>header=None, usecols=[7], names=['col8']</code></p>

<p>If you don't use <code>header=None</code> and <code>names</code> parameters, the first row will be used as a header:</p>

<pre><code>In [6]: df = pd.read_csv(fn, usecols=[7])

In [7]: df
Out[7]:
    8
0  18

In [8]: df.columns
Out[8]: Index(['8'], dtype='object')
</code></pre>

<p>and if we want to read only the last 10-<code>th</code> column:</p>

<pre><code>In [9]: df = pd.read_csv(fn, usecols=[10])
... skipped ...
ValueError: Usecols do not match names.
</code></pre>

<p>because pandas counts columns starting from <code>0</code>, so we have to do it this way:</p>

<pre><code>In [12]: df = pd.read_csv(fn, usecols=[9], names=['col10'])

In [13]: df
Out[13]:
   col10
0     10
1     20
</code></pre>

python pandas