Append new lines to the existing file in Pandas dataframe
<p>I have a python script that runs a query and stores it in a dataframe as below:</p>

<pre><code> df = pd.read_gbq(queryString, project_id=PROJECT)

 out = df.to_json(orient='records')[1:-1].replace('},{', '}\n{')
</code></pre>

<p>After some processing, I current store it in a json file:</p>

<pre><code>with open('/home/user/Downloads/Count1/Count.json', 'w') as f:
 f.write(out)
</code></pre>

<p>Every time when the program runs, it overwrites the existing file. I was just wondering whether there is a method in Python that appends only the new lines to the existing file rather than overwriting the entire file.</p>

<p>Any help would be appreciated !!</p>

<p>Try this: </p>

<pre><code>with open('/home/user/Downloads/Count1/Count.json', 'ab') as f:
     f.write(out)
</code></pre>

python file dataframe