Am trying to count the number of rows it takes for a certain row value 'Neg' to become 1 from its default 0 and capture this counts whereever Neg = 1 in a new column called 'dsf'. I tried the following code snippet, I'm not sure why but this puts 0 for all 'dsf' values.
Why is this wrong?
/code
full_data['dsf'] = 0
counter = 0
for i,r in full_data.iterrows():
if r['neg'] == 0:
counter+=1
r['dsf'] = 0
else:
r['dsf'] = counter
counter = 0
full_data
current output:
datehour pft rev mgn neg dsf
0 2018-04-01 00:00:00 53.1783 110.8514 0.479726 0 0
1 2018-04-01 00:30:00 51.1496 105.9060 0.482972 0 0
2 2018-04-01 01:00:00 42.9360 120.7555 0.355561 1 0
3 2018-04-01 01:30:00 37.8455 114.5514 0.330380 0 0
4 2018-04-01 02:00:00 43.9254 99.1340 0.443091 1 0
Ideal output:
datehour pft rev mgn neg dsf
0 2018-04-01 00:00:00 53.1783 110.8514 0.479726 0 0
1 2018-04-01 00:30:00 51.1496 105.9060 0.482972 0 0
2 2018-04-01 01:00:00 42.9360 120.7555 0.355561 1 3
3 2018-04-01 01:30:00 37.8455 114.5514 0.330380 0 0
4 2018-04-01 02:00:00 43.9254 99.1340 0.443091 1 2