将RPy2 ListVector转换为Python字典

将RPy2 ListVector转换为Python字典,第1张

将RPy2 ListVector转换为Python字典

我认为让ar向量进入a

dictionary
并不一定要如此,这是怎么回事:

In [290]:dict(zip(a.names, list(a)))Out[290]:{'fizz': <FloatVector - Python:0x08AD50A8 / R:0x10A67DE8>[123.000000], 'foo': <StrVector - Python:0x08AD5030 / R:0x10B72458>['barbat']}In [291]:dict(zip(a.names, map(list,list(a))))Out[291]:{'fizz': [123.0], 'foo': ['barbat']}

当然,如果您不介意使用

pandas
,它甚至更容易。结果将具有,
numpy.array
而不是
list
,但是在大多数情况下可以:

In [294]:import pandas.rpy.common as comcom.convert_robj(a)Out[294]:{'fizz': [123.0], 'foo': array(['barbat'], dtype=object)}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5647411.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存