Python Pandas: Write certain rows in file
<p>The csv file is way to big, so I am reading it chunk by chunk.
Therefore, I use read_csv with chunksize.</p>

<p>I want to store all rows, where the last entry has the value 1 in one file and all the other rows where the last entry is 0 in another file.</p>

<p>Suppose it looks like this:</p>

<pre><code>ID   A    B   C
0   0.0  0.1  1
1   0.1  0.2  0
2   0.1  0.0  1
</code></pre>

<p>So, I want to store row with ID 0 and 2 in one file and the row with ID 1 in another file.</p>

<p>How do I do that with pandas?</p>

<p>I would simply do it like this:</p>

<pre><code>first = True
df = pd.read_csv('file.csv', chunksize=1e5)
for chunk in df:
    if first:
        chunk[chunk['C'] == 1].to_csv('ones.csv', header=True)
        chunk[chunk['C'] == 0].to_csv('zero.csv', header=True)
        first = False
    chunk[chunk['C'] == 1].to_csv('ones.csv', header=False)
    chunk[chunk['C'] == 0].to_csv('zero.csv', header=False)
</code></pre>

python pandas