How to set/get Pandas dataframes into Redis using pyarrow

心已入冬 提交于 2019-12-04 09:55:21

Here's a full example to use pyarrow for serialization of a pandas dataframe to store in redis

apt-get install python3 python3-pip redis-server
pip3 install pandas pyarrow redis

and then in 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

I just submitted PR 28494 to pandas to include this pyarrow example in the docs.

Reference docs:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!