Make pandas.read_csv() ignore junk at the start of the csv files?
<p>I've got some junk at the start of my csv file that prevents me selecting the first column of my dataframe by name.</p>

<p>Example:</p>

<pre><code>In[1]: df = pd.read_csv('file:inputdata.csv', usecols=[0], nrows=1)

In[2]: df
Out[2]:
        TAB
0  10-LV_Non

In[3]: df['TAB']
Out[3]: &lt;snip&gt; KeyError: 'TAB'
</code></pre>

<p>I found the junk by reading the file with open():</p>

<pre><code>In[4]: with open('inputdata.csv', 'rb') as f:
           print(f.read(7))
Out[4]: b'\xef\xbb\xbfTAB,'
</code></pre>

<p>EDIT: <code>'\xef\xbb\xbf'</code> is three bytes of junk. <code>'TAB'</code> is the name of the first column.</p>

<p>Is there a way to make <code>pandas.read_csv()</code> ignore junks like this (if present) at the start of the csv file? </p>

<p>NB The csv files are exported from a proprietary system, so I can't control their format.</p>

<p>UPDATE: Here's my solution, based on Mike Müller's answer:</p>

<pre><code>with open('inputdata.csv', 'r') as f:
    # Skip past any bytes that aren't text
    while re.match('[a-zA-Z0-9_]', f.read(1)) is None:
        pass
    # Seek back one byte
    f.seek(f.tell()-1)
    # Read the file
    df = pd.read_csv(f, usecols=['TAB'])
</code></pre>