Read/Write APIΒΆ
Msgpacks can also be read from and written to strings.
In [1]: import pandas as pd
In [2]: from pandas_msgpack import to_msgpack, read_msgpack
In [3]: df = pd.DataFrame({'A': np.arange(10),
...: 'B': np.random.randn(10),
...: 'C': 'foo'})
...:
In [4]: to_msgpack(None, df)
Out[4]: b'\x84\xa4axes\x92\x86\xa4name\xc0\xa8compress\xc0\xa5dtype\xa6object\xa3typ\xa5index\xa4data\x93\xa1A\xa1B\xa1C\xa5klass\xa5Index\x86\xa4name\xc0\xa4stop\n\xa5start\x00\xa3typ\xabrange_index\xa4step\x01\xa5klass\xaaRangeIndex\xa5klass\xa9DataFrame\xa6blocks\x93\x86\xa6values\xc7P\x00 u\xa8\x8d\xd9h\xc8\xbf\xb7:\x9fCV7\xfb?\xd4\r\xd7\x16`6\xe2\xbf\x01IjK\xd6Y\xfa\xbf\x00(\xe2*B;\xe5?\xdc\x93\x82\xf6\x8f~\xca?\xe8\xff7\x98\xa1\x06\xea\xbfL\x95\x1eB}x\xc9\xbfa\xbe<98\xec\xce\xbf6\x8a\x8b8Y\xe5\xfe\xbf\xa5shape\x92\x01\n\xa4locs\x86\xa8compress\xc0\xa5shape\x91\x01\xa4ndim\x01\xa5dtype\xa5int64\xa4data\xd7\x00\x01\x00\x00\x00\x00\x00\x00\x00\xa3typ\xa7ndarray\xa5dtype\xa7float64\xa8compress\xc0\xa5klass\xaaFloatBlock\x86\xa6values\xc7P\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\xa5shape\x92\x01\n\xa4locs\x86\xa8compress\xc0\xa5shape\x91\x01\xa4ndim\x01\xa5dtype\xa5int64\xa4data\xd7\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa3typ\xa7ndarray\xa5dtype\xa5int64\xa8compress\xc0\xa5klass\xa8IntBlock\x86\xa6values\x9a\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa5shape\x92\x01\n\xa4locs\x86\xa8compress\xc0\xa5shape\x91\x01\xa4ndim\x01\xa5dtype\xa5int64\xa4data\xd7\x00\x02\x00\x00\x00\x00\x00\x00\x00\xa3typ\xa7ndarray\xa5dtype\xa6object\xa8compress\xc0\xa5klass\xabObjectBlock\xa3typ\xadblock_manager'
Furthermore you can concatenate the strings to produce a list of the original objects.
In [5]: read_msgpack(to_msgpack(None, df) + to_msgpack(None, df.A))
Out[5]:
[ A B C
0 0 -0.190700 foo
1 1 1.701010 foo
2 2 -0.569138 foo
3 3 -1.646933 foo
4 4 0.663484 foo
5 5 0.206987 foo
6 6 -0.813309 foo
7 7 -0.198990 foo
8 8 -0.241584 foo
9 9 -1.930993 foo, 0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
Name: A, dtype: int64]