How to get the last chunk of a csv file using Pandas?
<p>Suppose I have a csv file containing 5 rows.</p>

<p>Now I iterate over this file using a chunksize of 2.</p>

<pre><code>data = pd.read_csv(data_name, header=None, iterator=True, chunksize=2)
</code></pre>

<p>Suppose I am doing some magic on this data chunk and appending it to another csv file. </p>

<pre><code>processed_data.to_csv(fname, index=None, mode="a")
</code></pre>

<p><strong>Problem:</strong> The last row is not written.</p>

<p>I do not know how to solve this problem. Can someone help?</p>

<p>I need to use chunks because I don't have enough <strong>RAM</strong>.</p>

<p>I can not use <code>chunksize=1</code>, because opening/closing a file is too time consuming.</p>