我完全卡住了。在我的原始数据帧中,我有一列感兴趣的元素(荧光),我希望以固定的间隔(5)获取固定数量的元素(=3,黄色),并对它们进行平均。输出应保存到新列表中
fluorescence = df.iloc[1:20, 0]
fluorescence=pd.to_numeric(fluorescence)
## add a list to count
fluorescence['time']= list(range(1,20,1))
## create a list with interval
interval = list(range(1, 20, 5))
NewList=[]
for i in range(len(fluorescence)):
if fluorescence['time'][i] == interval[i]:
NewList.append(fluorescence[fluorescence.tail(3).mean()])
print(NewList)
欢迎任何意见!! 先谢谢你
这里,我将每5次连续迭代获取数据帧的子集,并获取尾部3行的平均值
如果您有一个数据列表,并且希望从每5个条目中提取3个条目,则可以按如下方式对列表进行分段:
相关问题 更多 >
编程相关推荐