要使用的RPY2作为.xts从XTS库

2024-09-28 23:15:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python中使用RPY2调用作为.xts“来自xts库的对象。”as'是python中的保留字。因此,我不确定如何继续使用作为.xts在我的python代码中。你知道吗

我的目的是作为.xts在具有时间序列列的现有数据帧上。你知道吗

from rpy2.robjects import pandas2ri
pandas2ri.activate()
r_dataframe = pandas2ri.py2ri(pandas_df)
from rpy2.robjects.packages import importr
xts= importr('xts', lib_loc="local path to R library" , robject_translations = {".subset.xts": "_subset_xts2", "to.period": "to_period2"})  
r_ts = as.xts(r_dataframe) # i am unsure of this step usage.  

我希望在最后一行代码的输出中有一个时间序列对象。我将在时间序列对象上使用forecast包。你知道吗


Tags: to对象代码fromimportdataframeas时间