import rpy2.robjects as ro
r=ro.r
data=[(15002325, 24, 20, 1393, -67333094L, 38, 4, 493.48763257822799, 493.63348372593703), (15002339, 76, 20, 1393, -67333094L, 91, 3, 499.95845909922201, 499.970048093743), (15002431, 24, 20, 1394, -67333094L, 38, 4, 493.493464900383, 493.63348372593703), (15002483, 76, 20, 1394, -67333094L, 91, 3, 499.959042442434, 499.97304310494502)]
columns=zip(*data)
columns=[ro.FloatVector(col) for col in columns]
names=['col{i}'.format(i=i) for i in range(9)]
dataf = r['data.frame'](**dict(zip(names,columns)))
print(dataf)
# col8 col6 col7 col4 col5 col2 col3 col0 col1
# 1 493.6335 4 493.4876 -67333094 38 20 1393 15002325 24
# 2 499.9700 3 499.9585 -67333094 91 20 1393 15002339 76
# 3 493.6335 4 493.4935 -67333094 38 20 1394 15002431 24
# 4 499.9730 3 499.9590 -67333094 91 20 1394 15002483 76
请注意,postgresql 有一个 R 接口,这可能提供比通过 Python 和 rpy2 更简洁的方法。
如果您需要 Python,另一种可能性是找出从 postgresql 加载数据所需的 R 命令,然后在 Python 中使用ro.r
.