我刚接触统计学。我手头有一个问题,我需要为质量控制的西部电气规则的所有4个规则编码。我已经能够在同事的帮助下编写第一个和第二个代码了,有谁能帮我写下规则4--“九个连续的点落在中心线的同一侧”
我通过获取低于和高于阈值的数据绘制了规则1,然后在单个单元格中运行matplotlib图。
我无法获取规则4的数据。
发布于 2019-06-18 20:27:40
即使没有人回答,这也给了我足够的动力去找出解决方案。虽然我知道我的代码不是最优的,但如果我需要进一步的修改,请给我建议。
temp_up=[]
temp_down=[]
for i in range(len(data)):
if arr_data[i] > y_mean:
temp_up.append(i)
else:
temp_down.append(i)
#now we have index values for both data above and below mean,
#we will now get the sequence of the index to know if there's any run of or greater than length 9
from itertools import groupby
from operator import itemgetter
d_up=[]
d_down=[]
for k, g in groupby(enumerate(temp_up), lambda ix : ix[0] - ix[1]):
t_up=(list(map(itemgetter(1), g)))
if len(t_up)>=9:#check if the length of the sequence is greater than or equal to 9
#get index to mark red for the data
for i in range(8, len(t_up), 1):
d_up.append(t_up[i])#index number of data points voilating number 4 rule (above mean)
for k, g in groupby(enumerate(temp_down), lambda ix : ix[0] - ix[1]):
t_down=(list(map(itemgetter(1), g)))
if len(t_down)>=9:#check if the length of the sequence is greater than or equal to 9
#print(t_down)
#get index to mark red for the data
for i in range(8, len(t_down), 1):
d_down.append(t_down[i])#index number of data points voilating number 4 rule (above mean)
data_above_r4 = pd.DataFrame(data.iloc[d_up])
https://stackoverflow.com/questions/56644307
复制相似问题