您必须将4列excel数据重塑为1列数据。
用于Matlab/gnuoctave的redis客户端正在这样做,例如:https://github.com/markuman/go-redis/wiki/Data-Structure#arrays
注意在这个例子中,Matlab/Octave使用的是列Major Order。
Python正在使用行主顺序:https://en.wikipedia.org/wiki/Row-major_order
因此,您必须将4列X行数据保存为redis中的row major order list as a list(RPUSH)。在
示例
给这个excel表格
使用这个python3代码#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 20 23:02:53 2015
@author: markus
"""
import pandas as pd
import redis
# redis connection
r = redis.StrictRedis(host='localhost', port=6379, db=0)
# open the first worksheed
df = pd.read_excel('/home/markus/excel.xlsx',0)
# read in as a list
# [[1, 'two', 'python'], ['excel', 'redis', 'action']]
a = list(df.T.itertuples())
print("this is a, your excel list")
print(a)
for list in a:
for value in list:
r.rpush('myexceldata', str(value))
# read all back to python
b = r.lrange('myexceldata', '0', '-1')
print("A1 becomes 0, B1 becomes 3 ...")
print(b[3].decode('UTF-8'))
在redis中将其序列化为列表保存
^{pr2}$
这只是在redis中保存电子表格的一种方法。它总是属于你的数据结构和你要用它做什么。在