我对Python还不熟悉。现在,我有一个数据帧,看起来像这样。你知道吗
DocumentId offset feature
0 0 2000
0 7 2000
0 16 0
0 27 0
0 36 0
0 40 0
0 46 0
0 57 0
0 63 0
0 78 0
0 88 0
0 91 0
0 103 2200
1 109 0
1 113 2200
1 126 2200
1 131 2200
1 137 2200
1 142 0
1 152 0
1 157 200
1 159 200
1 161 200
1 167 0
1 170 200
现在,在这个数据框中,我有一个名为feature
的列。它有一些值,其中也有一个值0
,其他值是positive values
。你知道吗
现在,每当正值变为零值,我们就要取它的前三个值。所以,我们假设它总是从正值开始。你知道吗
所以从这个数据集中
我会先得到结果的
offset1 feature offset2 feature offset3 feature
- - 0 2000 7 2000
for the `(-)` as it does not have the third value.
现在,它继续检查值,每当值从正到零变为正时,我就要取前三个值。你知道吗
所以,在这里
after 2200 which is at offset 103 value becomes the 0 which is at 109
现在,我必须取109 offset
的前三个值,这样数据就变成
offset1 feature offset2 feature offset3 feature
- - 0 2000 7 2000
103 2200 91 0 88 0
在这之后,从正到0的值变为偏移量142
,因此,我必须取前三个。你知道吗
offset1 feature offset2 feature offset3 feature
- - 0 2000 7 2000
103 2200 91 0 88 0
137 2200 131 2200 126 2200
161 200 159 200 157 200
offset4 feature offset5 feature offset6 feature
103 2200 109 0 113 2200
113 2200 126 2200 131 2200
157 200 159 200 161 200
所以,如果我们在数据帧中看到一个正数,如果我们向下,那么在
the place `103` the 0 becomes a positive value which is the 2200
现在,我取偏移量的下两个值.which are 109 and 113 and also the current number value which will be 103
因此,结果将是
offset4 feature offset5 feature offset6 feature
103 2200 109 0 113 2200
Now, after this If I go down, then immediately at 113 the previous value was 0 that gets changed to 2200
所以,我将取113后面的两个值,也就是126,131,那么下一个值就变成了
offset4 feature4 offset5 feature5 offset5 feature5
113 2200 126 2200 131 2200
Now again down then at 157 it gets changed to the 200 as so it will be same
。你知道吗
对于下一个值,我取下两个值和它本身,所以它变成3个值。在这里,每当值以这种方式从0 to a positive
更改时,我就取下一个值。你知道吗
我有什么办法能达到这个结果吗?谢谢。你知道吗
我试过的是
zero_indexes = list(input_with[input_csv['RFC_PREDICTEDFEATURE'] == 0].index)
df2 = pd.DataFrame()
for each_zero_index in zero_indexes:
value = input_with['feature'].loc[each_zero_index - 1: each_zero_index].values[0]
if value != 0 :
df1 = input_with.loc[each_zero_index - 3: each_zero_index]
df2 = df2.append(df1)
使用strides:
然后在
arr1
的第一个'column'
中为正值和下一个0值创建掩码:编辑:
相关问题 更多 >
编程相关推荐