Python。如何从包含不同时间间隔和长度的不同数值级数的列表中创建一个累积级数? [已关闭]

问题描述 投票:0回答:1

数据来自天文钟,分步测量值。例如,第一步每 30 次开始测量一次,但从 60 秒开始测量:

step_1 = [60,90,120]
,第二步:每 2 秒测量一次,持续 10 秒
step_2=[2,4,6,8,10]
。第三步每30秒一次:
step_3 = [30,60,90,120]
。每 30 秒第四步:
step_4 = [30,60,90]

我想从这个列表中选择:

time = [60,90,120,2,4,6,8,10,30,60,90,120]

要得到这个:

time_1=[60,90,120,122,124,126,128,130,160,190,220,260,290,320,350]
python pandas numpy time-series series
1个回答
0
投票
time_series = [60, 90, 120, 60, 90, 120, 150]
i = 1 # declare i =1 instead of 0
result = [time_series[0]] # with first element inside


while i < len(time_series):

    old_val = time_series[i-1]
    current_value = time_series[i]
    add = abs(old_val - current_value) # number to be added

    if current_value < result[-1]:
        current_value = result[-1] + add
    result.append(current_value)
    
    i += 1

print(result) # Output : [60, 90, 120, 180, 210, 240, 270]
© www.soinside.com 2019 - 2024. All rights reserved.