0

The other post I saw related to this topic involved using HDFStore which threw me off - I apologize if this is a redundant post. Let's say I have a list N of SQL type queries I would like to perform, where each output produces an individual panel.

N = [get_something(), get_something_else()...]

A single instance of run_query(get_something()) produces a panel that looks like this:

_panel = run_query(get_something())

<class 'pandas.core.panel.Panel'>
Dimensions: 1 (items) x 36 (major_axis) x 283 (minor_axis)
Items axis: shares_outstanding to shares_outstanding
Major_axis axis: 2015-07-30 00:00:00+00:00 to 2015-10-07 00:00:00+00:00
Minor_axis axis: Equity(2 [AA]) to Equity(49463 [KLDX])

When I try to iteratively build a panel using join or add, I get a variety of errors or blank output..

for item in N:
   _panel.join(run_query(item))

I guess what I am looking to do is to create and append to a panel just like a list.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • `.join` returns a new Panel, so you would need `_panel = _panel.join(run_query(item))` to affect the value of `_panel`. – unutbu May 17 '16 at 20:34
  • that sounds very reasonable. I'll give it a shot. Thank you! –  May 17 '16 at 20:41
  • PS: That definitely worked.. –  May 17 '16 at 20:45
  • Note that building an NDFrame (such as a Panel) through iterative calls to `.join` requires [quadratic copying](http://stackoverflow.com/a/36489724/190597). If the `join` is a simply concatenation, you'll get much better performance appending data to a list and building one Panel at the very end (outside the loop) with one call to `pd.Panel`. – unutbu May 17 '16 at 20:46
  • thank you unutbu. Unfortunately the data kind of arrives in panel form already through the query which I can do nothing about. Perhaps I could store each panel created as a dictionary entry and apply your suggestion at the end. Thanks again. –  May 17 '16 at 20:50

0 Answers0