pd.read_csv ignores columns that don't have headers
<p>I have a .csv file that is generated by a third-party program. The data in the file is in the following format:</p>

<pre><code>%m/%d/%Y    49.78   85  6   15                      
03/01/1984  6.63368 82  7   9.8 34.29056405 2.79984079  2.110346498 0.014652412 2.304545521 0.004732732
03/02/1984  6.53368 68  0   0.2 44.61471002 3.21623666  2.990408898 0.077444779 2.793385466 0.02661873
03/03/1984  4.388344    55  6   0   61.14463457 3.637231063 3.484310818 0.593098236 3.224973641 0.214360796
</code></pre>

<p>There are 5 column headers (row 1 in excel, columns A-E) but 11 columns in total (row 1 columns F-K are empty, rows 2-N contain float values for columns A-K)</p>

<p>I was not sure how to paste the .csv lines in so they are easily replicable, sorry for that. An image of the excel sheet is shown here: <a href="http://i.stack.imgur.com/UsJnk.png" rel="nofollow">Excel sheet to read in</a></p>

<p>when I use the following code:</p>

<pre><code>FWInds=pd.read_csv("path.csv")
</code></pre>

<p>or:</p>

<pre><code>FWInds=pd.read_csv("path.csv", header=None)
</code></pre>

<p>the resulting dataframe FWInds does not contain the last 6 columns - it only contains the columns with headers (columns A-E from excel, column A as index values). </p>

<pre><code>FWIDat.shape
Out[48]: (245, 4)
</code></pre>

<p>Ultimately the last 6 columns are the only ones I even want to read in.</p>

<p>I also tried:</p>

<pre><code>FWInds=pd.read_csv('path,csv', header=None, index_col=False)
</code></pre>

<p>but got the following error</p>

<pre><code>CParserError: Error tokenizing data. C error: Expected 5 fields in line 2, saw 11
</code></pre>

<p>I also tried to ignore the first row since the column titles are unimportant:</p>

<pre><code>FWInds=pd.read_csv('path.csv', header=None, skiprows=0)
</code></pre>

<p>but get the same error.</p>

<p>Also no luck with the "usecols" parameter, it doesn't seem to understand that I'm referring to the column numbers (not names), unless I'm doing it wrong:</p>

<pre><code>FWInds=pd.read_csv('path.csv', header=None, usecols=[5,6,7,8,9,10])
</code></pre>

<p>Any tips? I'm sure it's an easy fix but I'm very new to python.</p>

<p>You could do it as shown:</p>

<pre><code>col_name = list('ABCDEFGHIJK')
data = 'path.csv'
pd.read_csv(data, delim_whitespace=True, header=None, names=col_name, usecols=col_name[5:])
</code></pre>

<p><a href="http://i.stack.imgur.com/QqBJJ.png" rel="nofollow"><img src="http://i.stack.imgur.com/QqBJJ.png" alt="Image"></a></p>

<p>To read all the columns from A â K, simply omit the <code>usecols</code> parameter.</p>

<hr>

<p>Data:</p>

<pre><code>data = StringIO(
'''
%m/%d/%Y,49.78,85,6,15                      
03/01/1984,6.63368,82,7,9.8,34.29056405,2.79984079,2.110346498,0.014652412,2.304545521,0.004732732
03/02/1984,6.53368,68,0,0.2,44.61471002,3.21623666,2.990408898,0.077444779,2.793385466,0.02661873
03/03/1984,4.388344,55,6,0,61.14463457,3.637231063,3.484310818,0.593098236,3.224973641,0.214360796
''')

col_name = list('ABCDEFGHIJK')
pd.read_csv(data, header=None, names=col_name, usecols=col_name[5:])
</code></pre>

python csv pandas