Her er et fuldstændigt eksempel på at bruge pyarrow til serialisering af en pandas dataramme til lagring i redis
apt-get install python3 python3-pip redis-server
pip3 install pandas pyarrow redis
og derefter i python
import pandas as pd
import pyarrow as pa
import redis
df=pd.DataFrame({'A':[1,2,3]})
r = redis.Redis(host='localhost', port=6379, db=0)
context = pa.default_serialization_context()
r.set("key", context.serialize(df).to_buffer().to_pybytes())
context.deserialize(r.get("key"))
A
0 1
1 2
2 3
Jeg har lige indsendt PR 28494 til pandaer for at inkludere dette pyarrow-eksempel i dokumenterne.
Referencedokumenter:
- https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_msgpack.html
- https://arrow.apache.org/docs/python/ipc.html#arbitrary-object-serialization
- https://arrow.apache.org/docs/python/memory.html#pyarrow-buffer
- https://stackoverflow.com/a/37957490/4126114