Storing Dataframe with Array Entries
<p>I have a Pandas DataFrame with the following structure, which contains both numbers and numpy arrays of fixed shape:</p>

<pre><code>import pandas as pd
import numpy as np

df = pd.DataFrame({"num":(23, 42), "list":(np.arange(3), np.arange(1,4))
</code></pre>

<p>Assuming I have large (more than 1 GB) amounts of this data that I would like to store and retrieve quickly, how should I go about storing it? If I use HDF5, the Numpy array gets pickled which will affect the ability to retrieve the data quickly. Is there some way to tell HDF5 how to store Numpy arrays? Alternatively, should I not be using HDF5 at all?</p>

<p>The following GitHub thread seems to suggest the following:</p>

<ol>
<li>Create a function that gets the desired Numpy array, which is stored in some other format <a href="https://github.com/pydata/pandas/issues/3032#issuecomment-15016217" rel="nofollow">[1]</a></li>
<li>Create a class to inform HDF5 <a href="https://github.com/pydata/pandas/issues/3032#issuecomment-15016217" rel="nofollow">[2]</a></li>
</ol>

<p>Both of these solutions seem oddly specific for how common I imagine this problem to be. Are there more general approaches? Am I just using the wrong tool?</p>

<p>I mean something like this:</p>

<pre><code>df_x = pd.concat([df.num, pd.DataFrame(np.vstack(df.list))], 
                 keys=["key", "arr"], axis=1)
</code></pre>

<p>the dataframe:</p>

<pre><code>  key arr      
  num   0  1  2
0  23   0  1  2
1  42   1  2  3
</code></pre>

<hr>

<p>convert back with:</p>

<pre><code>pd.concat([df_x.key, pd.Series(tuple(df_x.arr.values), name='list')], axis=1)

   num       list
0   23  [0, 1, 2]
1   42  [1, 2, 3]
</code></pre>

python pandas numpy serialization