Python Pandas: Best strategy to import heterogenious csv file
<p>I have a inhomogenious csv-File I want to read into pandas. The file looks like that:</p>

<pre><code>2016-01-01; 1.00; 2.00
2016-01-02; 1,10; 2.05
2016-01-03; 0.95; 1.90
Some other text in here
2016-01-04; 1.01; 2.04
Some more text there
2016-01-05; 1.06; 2.07
</code></pre>

<p>I only need the text lines so I can skip the lines starting with a date. I tried several strategies to read that in and filter our the required data but nothing worked so far. What I know is the Text-lines always start with a special word ("some" in this example). However, there is no fixed line number that can be used.</p>

<p>If you'd like to discard lines starting with a single special <em>character</em>, you can use the <code>comment</code> parameter of <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>read_csv</code></a>, as noted by @cel in the comment above. </p>

<p>Otherwise, you can use regular Python logic for filtering out items from an iterator, and use <code>CStringIO</code>.</p>

<p>For example, to discard the lines starting with <code>"some"</code>, you can use:</p>

<pre><code>import CStringIO

buf = StringIO.StringIO('\n'.join((l for l in open('stuff.txt') if not l.startswith('Some'))))
pd.read_csv(buf, sep=';')
</code></pre>

<p>Conversely, if you actually only need lines starting with <code>"some"</code>, then use</p>

<pre><code>buf = StringIO.StringIO('\n'.join((l for l in open('stuff.txt') if l.startswith('Some'))))
</code></pre>

python pandas