problems dealing with pandas read csv
<p>I've got a problem with pandas read_csv. I had a many txt files that associate with stock market.It's like this:</p>

<pre><code>SecCode,SecName,Tdate,Ttime,LastClose,OP,CP,Tq,Tm,Tt,Cq,Cm,Ct,HiP,LoP,SYL1,SYL2,Rf1,Rf2,bs,s5,s4,s3,s2,s1,b1,b2,b3,b4,b5,sv5,sv4,sv3,sv2,sv1,bv1,bv2,bv3,bv4,bv5,bsratio,spd,rpd,depth1,depth2  
600000,æµ¦åé¶è¡,20120104,091501,8.490,.000,.000,0,.000,0,0,.000,0,.000,.000,.000,.000,.000,.000, ,.000,.000,.000,.000,8.600,8.600,.000,.000,.000,.000,0,0,0,0,1100,1100,38900,0,0,0,.00,.000,.00,.00,.00
600000,æµ¦åé¶è¡,20120104,091506,8.490,.000,.000,0,.000,0,0,.000,0,.000,.000,.000,.000,.000,.000, ,.000,.000,.000,.000,8.520,8.520,.000,.000,.000,.000,0,0,0,0,56795,56795,33605,0,0,0,.00,.000,.00,.00,.00
600000,æµ¦åé¶è¡,20120104,091511,8.490,.000,.000,0,.000,0,0,.000,0,.000,.000,.000,.000,.000,.000, ,.000,.000,.000,.000,8.520,8.520,.000,.000,.000,.000,0,0,0,0,56795,56795,34605,0,0,0,.00,.000,.00,.00,.00
600000,æµ¦åé¶è¡,20120104,091551,8.490,.000,.000,0,.000,0,0,.000,0,.000,.000,.000,.000,.000,.000, ,.000,.000,.000,.000,8.520,8.520,.000,.000,.000,.000,0,0,0,0,56795,56795,35205,0,0,0,.00,.000,.00,.00,.00
600000,æµ¦åé¶è¡,20120104,091621,8.490,.000,.000,0,.000,0,0,.000,0,.000,.000,.000,.000,.000,.000, ,.000,.000,.000,.000,8.520,8.520,.000,.000,.000,.000,0,0,0,0,57795,57795,34205,0,0,0,.00,.000,.00,.00,.00
</code></pre>

<p>while I use this code to read it :</p>

<pre><code>fields = ['SecCode', 'Tdate','Ttime','LastClose','OP','CP','Rf1','Rf2']  
df = pd.read_csv('SHL1_TAQ_600000_201201.txt',usecols=fields)
</code></pre>

<p>But I got a problem: </p>

<pre><code>Traceback (most recent call last):
  File "E:/workspace/Senti/highlevel/highlevel.py", line 8, in &lt;module&gt;
    df = pd.read_csv('SHL1_TAQ_600000_201201.txt',usecols=fields,header=1)
  File "D:\Anaconda2\lib\site-packages\pandas\io\parsers.py", line 562, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "D:\Anaconda2\lib\site-packages\pandas\io\parsers.py", line 315, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "D:\Anaconda2\lib\site-packages\pandas\io\parsers.py", line 645, in __init__
    self._make_engine(self.engine)
  File "D:\Anaconda2\lib\site-packages\pandas\io\parsers.py", line 799, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
  File "D:\Anaconda2\lib\site-packages\pandas\io\parsers.py", line 1257, in __init__
    raise ValueError("Usecols do not match names.")
ValueError: Usecols do not match names.
</code></pre>

<p>I can't find any problem similar to mine.And also it's wired when I copy the txt file into another one ,the code runs well,but the original one cause the above problem.How can I solve it ?</p>

<p>In your message, you said that you're a running:</p>

<pre><code>df = pd.read_csv('SHL1_TAQ_600000_201201.txt',usecols=fields)
</code></pre>

<p>Which did not throw an error for me and @Anil_M. But from your traceback, it is possible to see that the command used is another one:</p>

<pre><code>df = pd.read_csv('SHL1_TAQ_600000_201201.txt',usecols=fields, header=1)
</code></pre>

<p>which includes a <code>header=1</code> and it throws the error mentioned.</p>

<p>So, I would guess that the error comes from some confusion on your code.</p>

python pandas