title: Pandas DataFrame and Series - IB TWS HistoricalData
body: <p>I am trying to apply the pandas module to my code in order to re-organize the messages received back from IB TWS server.</p>
  <p>The code is</p>
  <pre><code>from ibapi.client import EClient
  from ibapi.wrapper import EWrapper
  from ibapi.contract import Contract
  
  
  class MyWrapper(EWrapper):
  
      def nextValidId(self, orderId:int):
          print(&quot;Setting nextValidOrderId: %d&quot;, orderId)
          self.nextValidOrderId = orderId
          self.start()
  
      def historicalData(self, reqId, bar):
          print(&quot;HistoricalData. &quot;, reqId, &quot;Date:&quot;, bar.date, &quot;Open:&quot;, bar.open, &quot;High:&quot;, bar.high, &quot;Low:&quot;, bar.low, &quot;Close:&quot;, bar.close, &quot;Volume:&quot;, bar.volume, &quot;Average:&quot;, bar.average, &quot;Count:&quot;, bar.barCount)
  
      def historicalDataUpdate(self, reqId, bar):
          print(&quot;HistoricalDataUpdate. &quot;, reqId, &quot;Date:&quot;, bar.date, &quot;Open:&quot;, bar.open, &quot;High:&quot;, bar.high, &quot;Low:&quot;, bar.low, &quot;Close:&quot;, bar.close, &quot;Volume:&quot;, bar.volume, &quot;Average:&quot;, bar.average, &quot;Count:&quot;, bar.barCount)
  
      def error(self, reqId, errorCode, errorString):
          print(&quot;Error. Id: &quot; , reqId, &quot; Code: &quot; , errorCode , &quot; Msg: &quot; , errorString)
  
      def start(self):
          queryTime = &quot;&quot;
  
          contract = Contract()
          contract.secType = &quot;STK&quot;
          contract.symbol = &quot;NIO&quot;
          contract.currency = &quot;USD&quot;
          contract.exchange = &quot;SMART&quot;
  
          app.reqHistoricalData(1, contract, queryTime, &quot;1 D&quot;, &quot;5 secs&quot;, &quot;TRADES&quot;, 0, 1, True, [])
  
  app = EClient(MyWrapper())
  app.connect(&quot;127.0.0.1&quot;, 7496, clientId=123)
  app.run()
  </code></pre>
  <p>This code retrives historical data for a given stock, then returns the most current updates.</p>
  <p>The problem that I am facing is that the messages returned are organized as such</p>
  <pre><code>HistoricalDataUpdate.  1 Date: 20200708  08:31:00 Open: 14.17 High: 14.17 Low: 14.17 Close: 14.17 Volume: -1 Average: 14.15 Count: -1
  </code></pre>
  <p>While I am trying to retrieve the data in a re-organized manner such as</p>
  <pre><code>HistoricalDataUpdate.  1 Date:            Open:  High:  Low:   Close:  Volume:  Average:  Count:
                         20200708  08:31:00 14.17  14.17  14.17  14.17   -1       14.15     -1
  </code></pre>
  <p>Help would be appreciated.</p>