我处理了大量的时间序列刻度数据,并且我正在尝试使用rpy2将这些数据从Python中提取到R.具体来说,我想要传输包含毫秒时间戳的时间序列(关键)和时区信息(很好)。
为了测试传输时间戳,我尝试了:
from pytz import timezone
from datetime import datetime
import rpy2.robjects as robjects
# 1 microsecond into 2015 in US Eastern time
time = datetime(2015,1,1,0,0,0,1, tzinfo = timezone('US/Eastern'))
robjects.r.assign('time', time)
但是这给了:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python\2.7\lib\site-packages\rpy2\robjects\functions.py", line 170, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "C:\Python\2.7\lib\site-packages\rpy2\robjects\functions.py", line 96, in __call__
new_args = [conversion.py2ri(a) for a in args]
File "C:\Python\2.7\lib\site-packages\singledispatch.py", line 210, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
File "C:\Python\2.7\lib\site-packages\rpy2\robjects\conversion.py", line 39, in py2ri
raise NotImplementedError("Conversion 'py2ri' not defined for objects of type '%s'" % str(type(obj)))
NotImplementedError: Conversion 'py2ri' not defined for objects of type '<type 'datetime.datetime'>'
似乎rpy2不支持datetime
个对象...那么如何将时间序列传输到R?
答案 0 :(得分:1)
R中有几种日期/时间对象。
例如:
robjects.POSIXct([time])
如果您知道,可以快速将转化规则添加到rpy2