title: append overwriting dataframe python
body: <p>I have a function which is called each time a message is received, I am trying to append information to a dataframe as it comes in, but when I open it I only see the final message to be received is in the dataframe.</p>
  <p>My code is below</p>
  <pre><code>def on_message(client, userdata,  message):
      df = pd.DataFrame()
      topic = message.topic
      new_row = {'message':message, 'topic': topic}
      df = df.append(new_row, ignore_index=True)
      df.to_csv('output.csv')
  </code></pre>