我尝试将不规则数据插入到每月分辨率。错误是这样的 enter image description here
文件“/usr/local/lib/python2.7/dist-packages/traces/timeseries.py”,第122行,位于_get_linear_interpolate 返回self.default 文件“/usr/local/lib/python2.7/dist-packages/traces/timeseries.py”,第106行,默认 提出KeyError(msg) KeyError:“没有测量值(或默认值)无法获得值” 代码是这样的:
import datetime
from datetime import timedelta
import traces
import re
import os
ls = []
def cal_time_series(_ff):
with open(_ff) as _fi:
for _l in _fi.read().splitlines():
_vv = _l.split(',')
if _vv[0] == 'date':
continue
_date = _vv[0].split('-')
ls.append((datetime.datetime(int(_date[0]),int(_date[1]),int(_date[2])),int(_vv[1])))
ts = traces.TimeSeries(ls)
ts.sample(sampling_period=datetime.timedelta(days=30),start=datetime.datetime(2000,1,15),end=datetime.datetime(2015,12,15),interpolate='linear',)
cal_time_series('/mnt/d/thesis/code/point1.csv')
答案 0 :(得分:0)
您的代码存在缩进问题:
if _vv[0] == 'date':
continue
_date = _vv[0].split('-')
ls.append((datetime.datetime(int(_date[0]),int(_date[1]),int(_date[2])),int(_vv[1])))
底部的两行永远不会被击中,因为迭代会在之前继续。