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\xa6blocks\x93\x86\xa5shape\x92\x01\n\xa5dtype\xa7float64\xa4locs\x86\xa5shape\x91\x01\xa5dtype\xa5int64\xa3typ\xa7ndarray\xa8compress\xc0\xa4data\xd7\x00\x01\x00\x00\x00\x00\x00\x00\x00\xa4ndim\x01\xa8compress\xc0\xa6values\xc7P\x00[n\x15<\x19\x99\x90?ZtL\x95\x8dI\xd7?\x18\xff\x1d:\x98\x86\xe7\xbf\xe1\xd0\xab\xd9\xa9\xcc\xf3\xbf\x8c\xf3\x85\xbf\xc4\xd3\xea\xbf8\x1c\xb1I\xc0\xf0\xf7\xbf\xd0#c8\x9f\xb6\xb8\xbfJ\xab\x05fj\xa3\xdc?\x15#J\xd2\x95\xef\x08@\xae\xd1\xa7Y\x0c\x01\xd5?\xa5klass\xaaFloatBlock\x86\xa5shape\x92\x01\n\xa5dtype\xa5int64\xa4locs\x86\xa5shape\x91\x01\xa5dtype\xa5int64\xa3typ\xa7ndarray\xa8compress\xc0\xa4data\xd7\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4ndim\x01\xa8compress\xc0\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\xa5klass\xa8IntBlock\x86\xa5shape\x92\x01\n\xa5dtype\xa6object\xa4locs\x86\xa5shape\x91\x01\xa5dtype\xa5int64\xa3typ\xa7ndarray\xa8compress\xc0\xa4data\xd7\x00\x02\x00\x00\x00\x00\x00\x00\x00\xa4ndim\x01\xa8compress\xc0\xa6values\x9a\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa3foo\xa5klass\xabObjectBlock\xa4axes\x92\x86\xa8compress\xc0\xa5dtype\xa6object\xa3typ\xa5index\xa4name\xc0\xa4data\x93\xa1A\xa1B\xa1C\xa5klass\xa5Index\x86\xa4stop\n\xa3typ\xabrange_index\xa5start\x00\xa4name\xc0\xa4step\x01\xa5klass\xaaRangeIndex\xa5klass\xa9DataFrame\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.016209 foo
1 1 0.363864 foo
2 2 -0.735180 foo
3 3 -1.237467 foo
4 4 -0.838351 foo
5 5 -1.496277 foo
6 6 -0.096537 foo
7 7 0.447474 foo
8 8 3.116985 foo
9 9 0.328189 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]