仪器的探头沿x方向往回走,同时记录其位置并获取测量结果。探测器产生10个周期,比方说从0到10嗯(来回)并记录测量结果。这给出了两列数据:位置和测量,其中位置数循环0 0um>10->0->10->0.但是这些数字有一个实验误差,所以它们都不同。
我需要在每个周期开始的时候分割数据。有什么有趣的策略来解决这个问题吗?如果你需要更多的信息请告诉我。提前谢谢。
下面链接到我所拥有的dataframe示例。https://www.dropbox.com/s/af4r8lw5lfhwexr/Example.xlsx?dl=0
在这个例子中,仪器做了3个周期并生成数据(测量)。周期1=指数0-20;周期1=指数20-40;周期1=指数40-60.我需要把这个数据分成3个数据,每个周期一个(索引0-20;索引20-40;索引40-60)。
棘手的部分是,该方法需要“通用”,因为每个周期可以有不同数量的数据点(在本例中是固定为20),并且可以用不同的周期执行不同的实验。
发布于 2020-12-05 21:59:59
我的目标是,当数字在下降后再次增加时,保持域,以确定循环数。不太优雅抱歉。
import pandas as pd
df = pd.read_excel('Example.xlsx')
def cycle(array):
increasing = 1
cycle_num = 0
answer = []
for ind,val in enumerate(array):
try:
if array[ind+1]-array[ind]>=0:
if increasing==0:
cycle_num+=1
increasing=1
answer.append(cycle_num)
else:
answer.append(cycle_num)
increasing=0
except:
answer.append(cycle_num)
return answer
df['Cycle'] = cycle(df['Distance'].to_list())
grouped = df.groupby(['Cycle'])
print(grouped.get_group(0))
print(grouped.get_group(1))
print(grouped.get_group(2))https://stackoverflow.com/questions/65161029
复制相似问题