I want to keep only the value of the first instance of a sequence, following values to be set to zero. If the value repeats again later in the series, it should also be captured. e.g -265.95745849609375 is present at the top and at the bottom
*
s1
Index value
847.7248427790372 -265.95745849609375
847.7448445792772 -265.95745849609375
847.8448535804773 -265.95745849609375
847.8648553807175 -480.0611789817236
847.8848571809574 -714.2857666015625
848.0048679823976 -714.2857666015625
848.0248697826377 -714.2857666015625
.... .....
849.0449615948793 -714.2857666015625
849.0649633951193 -550.6575933264419
849.0849651953594 -446.4285583496094
849.1849741965596 -446.4285583496094
... ...
849.2449795972797 -446.4285583496094
849.8650354047206 -248.9522315559211
849.8850372049607 -265.95745849609375
849.9050390052007 -265.95745849609375
849.9250408054407 -265.95745849609375
*
Expected outcome:
*
847.7248427790372 -265.95745849609375
847.7448445792772 0
847.7648463795173 0
847.8648553807175 -480.0611789817236
847.8848571809574 -714.2857666015625
847.9048589811974 0
847.9248607814375 0
848.0248697826377 0
.... .....
849.0449615948793 0
849.0649633951193 -550.6575933264419
849.0849651953594 -446.4285583496094
849.1049669955994 0
849.1249687958394 0
849.1849741965596 0
... ...
849.2449795972797 0
849.8650354047206 -248.9522315559211
849.8850372049607 -265.95745849609375
849.9050390052007 0
849.9250408054407 0
Code I used
for outer in range(1,len(s1['value'])-1):
if s1['value'].values[outer] == s1['value'].values[outer+1]:
for inner in range(outer,len(s1['value'])):
if s1['value'].values[outer] == s1['value'].values[inner]:
s1['value'].values[inner] = 0
outer=inner+1
But it takes longer time to execute this as the number of elements in the series is normally 30000 and above. Can any one help with a better and faster way to do this? Thanks in advance.