title: Pandas: Continuously write from function to csv
body: <p>I have a function set up for <code>Pandas</code> that runs through a large number of rows in <code>input.csv</code> and inputs the results into a Series. It then writes the Series to <code>output.csv</code>.</p>
  
  <p>However, if the process is interrupted (for example by an unexpected event) the program will terminate and all data that would have gone into the csv is lost.</p>
  
  <p>Is there a way to write the data continuously to the csv, regardless of whether the function finishes for all rows?</p>
  
  <p>Prefarably, each time the program starts, a blank <code>output.csv</code> is created, that is appended to while the function is running.</p>
  
  <pre><code>import pandas as pd
  
  df = pd.read_csv("read.csv")
  
  def crawl(a):
      #Create x, y
      return pd.Series([x, y])
  
  df[["Column X", "Column Y"]] = df["Column A"].apply(crawl)
  df.to_csv("write.csv", index=False)
  </code></pre>