I want to process stock level-2 data in pandas. Suppose there are four kinds data in each row for simplicity:

* millis: timestamp, int64
* last\_price: the last trade price, float64,
* ask\_queue: the volume of ask side, a fixed size (200) array of int32
* bid\_queue: the volume of bid side, a fixed size (200) array of int32

Which can be easily defined as a structured dtype in numpy:

```
dtype = np.dtype([
   ('millis', 'int64'), 
   ('last_price', 'float64'), 
   ('ask_queue', ('int32', 200)), 
   ('bid_queue', ('int32', 200))
])

```

And in that way, I can access the `ask_queue` and `bid_queue` like:

```
In [17]: data = np.random.randint(0, 100, 1616 * 5).view(dtype)

% compute the average of ask_queue level 5 ~ 10
In [18]: data['ask_queue'][:, 5:10].mean(axis=1)  
Out[18]: 
array([33.2, 51. , 54.6, 53.4, 15. , 37.8, 29.6, 58.6, 32.2, 51.6, 34.4,
       43.2, 58.4, 26.8, 54. , 59.4, 58.8, 38.8, 35.2, 71.2])

```

My question is how to define a `DataFrame` include the data?

There are two solutions here:

**A. set the `ask_queue` and `bid_queue` as two columns with array values as following:**

```
In [5]: df = pd.DataFrame(data.tolist(), columns=data.dtype.names)

In [6]: df.dtypes
Out[6]: 
millis          int64
last_price    float64
ask_queue      object
bid_queue      object
dtype: object

```

However, there at least two problems in this solution:

1. The `ask_queue` and `bid_queue` lost the dtype of 2D array and all
the convenient methods;
2. Performance, since it become a array of objects rather than a 2D
array.

**B. flatten the `ask_queue` and `bid_quene` to `2 * 200` columns:**

```
In [8]: ntype = np.dtype([('millis', 'int64'), ('last_price', 'float64')] + 
   ...:                  [(f'{name}{i}', 'int32') for name in ['ask', 'bid'] for i in range(200)])

In [9]: df = pd.DataFrame.from_records(data.view(ntype))

In [10]: df.dtypes
Out[10]: 
millis          int64
last_price    float64
ask0            int32
ask1            int32
ask2            int32
ask3            int32
ask4            int32
ask5            int32
...

```

It's better than solution A. But the 2 \* 200 columns looks redundant.

Is there any solution can take the advantage as the structured dtype in numpy?
I wonder if the `ExtensionArray` or `ExtensionDtype' can solve this.