title: Insert or Update a delta table from a dataframe in Pyspark
body: <p>I have a pyspark dataframe currently from which I initially created a delta table using below code -</p>
  <pre><code>df.write.format(&quot;delta&quot;).saveAsTable(&quot;events&quot;)
  </code></pre>
  <p>Now, since the above dataframe populates the data on daily basis in my requirement, hence for appending new records into delta table, I used below syntax -</p>
  <pre><code>df.write.format(&quot;delta&quot;).mode(&quot;append&quot;).saveAsTable(&quot;events&quot;)
  </code></pre>
  <p>Now this whole thing I did in databricks and in my cluster. I want to know how can I write generic pyspark code in python that will create delta table if it does not exists and append records if delta table exists.This thing I want to do because if I give my python package to someone, they will not have the same delta table in their environment so it should get created dynamically from code.</p>