我需要使用像这样的pandas.DataFrame.resample函数重新采样数据帧:
data.set_index('TIMESTAMP').resample('24min', how='sum')
这没有问题,但是当我尝试使用'xmin'调用fucntion时,x是一般的段
data.set_index('TIMESTAMP').resample('xmin', how='sum')
无法运作
请问好吗?
谢谢
修改
def ratio_activ_equip(data, date_deb, date_fin, step):
# filtre_site(data, site)
filtre_date(data, date_deb, date_fin)
xmin = 'stepmin'
data.set_index('TIMESTAMP').resample(xmin, how='sum')
res = data.iloc[:,1:10] = data.iloc[:,1:10].divide(data.sum(axis=1), axis=0)
res = data
return res
EDIT2
def ratio_activ_equip(data, date_deb, date_fin, step): #
# filtre_site(data, site)
filtre_date(data, date_deb, date_fin)
#step = 10
xmin = str(step) + 'min'
data = data.set_index('TIMESTAMP').resample(xmin, how='sum')
data.set_index('TIMESTAMP').resample(xmin, how='sum')
res = data.iloc[:,1:10] = data.iloc[:,1:10].divide(data.sum(axis=1), axis=0)
res = data
return res
当我这样称呼这个问题时:
res = ratio_activ_equip(y, '2016-05-10 22:00:00', '2016-05-14 22:00:00', 30)
我收到此错误:
KeyError: 'TIMESTAMP'
请问好吗?
答案 0 :(得分:1)
IIUC您需要传递变量xmin
:
xmin = '24min'
data.set_index('TIMESTAMP').resample(xmin, how='sum')
更一般的是将int
值转换为str
并添加子字符串min
:
step = 10
xmin = str(step) + 'min'
data = data.set_index('TIMESTAMP').resample(xmin, how='sum')
step = 10
data = data.set_index('TIMESTAMP').resample(str(step) + 'min', how='sum')