Selectively feeding python csv class with lines
<p>I have a csv file with a few patterns. I only want to selectively load lines into the csv reader class of python. Currently, csv only takes a file object. Is there a way to get around this?<br>
In other words, what I need is:</p>

<pre><code>with open('filename') as f:
    for line in f:
        if condition(line):
            record = csv.reader(line)
</code></pre>

<p>But, currently, csv class fails if it is given a line instead of a file object.</p>

<p>```</p>

<pre><code>with open("xx.csv") as f:
    csv = f.readlines()
    print(csv[0])
</code></pre>

<p>```</p>

<p>â_â Life is short,your need pandas</p>

<p>pip install pandas</p>

<p>```</p>

<pre><code>import pandas as pd
df = pd.read_csv(filepath or url)
df.ix[0]
df.ix[1]
df.ix[1:3]
</code></pre>

<p>```</p>

python csv