a b
0 0
1 1
2 1
0 0
1 0
2 1
现在我要做以下事情: 创建一个新的列c,对于a = 0的每一行用1填充c然后c应该用1填充,直到每列满足后的第一行,其中b = 1(这里是挂起),所以输出应该是这样的:
a b c
0 0 1
1 1 1
2 1 0
0 0 1
1 0 1
2 1 1
谢谢!
答案 0 :(得分:2)
似乎你需要:
//------------------------------------------------
Roi.getBounds(rx, ry, width, height);
row = 0;
for(y=ry; y<ry+height; y++) {
for(x=rx; x<rx+width; x++) {
if(Roi.contains(x, y)==1) {
setResult("X", row, x);
setResult("Y", row, y);
setResult("Value", row, getPixel(x, y));
row++;
}
}
}
//------------------------------------------------
<强>详细强>:
df['c'] = df.groupby(df.a.eq(0).cumsum())['b'].cumsum().le(1).astype(int)
print (df)
a b c
0 0 0 1
1 1 1 1
2 2 1 0
3 0 0 1
4 1 0 1
5 2 1 1