在我的数据集中,我需要找出S重复超过280次的0‘的个数,并取回数组中重复开始的第一个行号.我使用的是Python3.11.
样本数据:
差异
0
0
0
0
0
0
0
.
.
.
5
5
.
.
0
0
0
0
或者创建样本数据集:
ACD=[0,5]
df2 = pd.DataFrame(np.repeat(ACD, 100, axis=0))
df3=df2.sample(frac=1,axis=1).sample(frac=1).reset_index(drop=True)
到目前为止,我的代码是:
c=[]
for values,row in df.loc[:, ['差异']].iterrows():
i=0
while row['差异'] == 0:
count = sum(1 for i in row)
i +=1
if count > 280:
continue
c.append(np.where(row['差异']))
else:
values+=1
预期输出:
row_number_rep= [5,90,120] #showing the specific row numbers where the repetition stars.
我对Python 还是个新手.
在这段代码中,我得到错误":8:DeposationWarning:不建议对0d数组调用非零值,因为它的行为令人惊讶.如果是有意使用旧行为,则使用atleast_1d(arr).nonzero()
."
我需要帮助来改进这个代码.我想问题是我没有像0‘S那样的前280项,我需要不断地迭代整列以找到0’S重复280次的所有行号.
非常感谢!