title: consume events in python azure event hub
body: <p>I am receiving JSON data in event hub.</p>
  <p>Once a day I want to read this data from event hub and store it in a database. In order to read the data from event hub I am following this documentation: <a href="https://docs.microsoft.com/en-us/python/api/overview/azure/eventhub-readme?view=azure-python" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/python/api/overview/azure/eventhub-readme?view=azure-python</a></p>
  <p>I am able to print all the events that I have in my event hub, but I don't know how to get these events and return a pandas dataframe outside of this function.</p>
  <p>I have tried this:</p>
  <pre class="lang-py prettyprint-override"><code>
  def on_event_batch(partition_context, events):
      final_dataframe = pd.DataFrame()
      print(&quot;Received event from partition {}&quot;.format(partition_context.partition_id))
      for event in events:
          
          body = json.loads(next(event.body).decode('UTF-8'))
          event_df  = pd.DataFrame(body,index = [0])
          final_dataframe = pd.concat([final_dataframe,event_df],ignore_index= True)
      partition_context.update_checkpoint()
      client.close()
      print(final_dataframe)
      return final_dataframe
      
  with client:
      final_dataframe = client.receive_batch(
          on_event_batch=on_event_batch, 
          starting_position=&quot;-1&quot;,  # &quot;-1&quot; is from the beginning of the partition.
      )
      
      # receive events from specified partition:
      # client.receive_batch(on_event_batch=on_event_batch, partition_id='0')
  </code></pre>
  <p>but it is not working.</p>