Я думаю, что я получаю то, что вам нужно, хотя функция его получения немного сложна. Я объясняю свой код в комментариях для случая со значениями, меньшими, чем 0,02, но для случаев, больше чем 0,02, логика c точно такая же.
import pandas as pd
a=[0.04, 0.04, 0.02, 0.02, 0.03, 0.03, 0.02, 0.01]
adf=pd.DataFrame(a, columns=["ENTRYP"])
def afunct(ent):
stats=["MOVEMENT_","ENT_EXT"]
c_status=[]
m_counter=0
e_counter=0
for i in ent:
if(i <= 0.02): # cases when the value is less equal that 0.02 (it's ENT_EXT")
if(len(c_status)==0): # if the list is empty we initialize the counters for "M" and "E" and put the first STATUS
m_counter=0
e_counter=1
c_status.append("{}{}".format(stats[1],e_counter ))
elif(c_status[-1][0]=="E"): ## if the last status is a "E" we just add another "ENT_EXT"
c_status.append("{}{}".format(stats[1],e_counter ))
elif(c_status[-1][0]=="M"): # if the last status is a "M" we add to the e_counter and assign STATUS
e_counter+=1
c_status.append("{}{}".format(stats[1],e_counter ))
elif(i>0.02):
if(len(c_status)==0):
m_counter=1
e_counter=0
c_status.append("{}{}".format(stats[0],m_counter ))
elif(c_status[-1][0]=="M"):
c_status.append("{}{}".format(stats[0],m_counter ))
elif(c_status[-1][0]=="E"):
m_counter+=1
c_status.append("{}{}".format(stats[0],m_counter ))
return(c_status)
adf["STATUS"]=afunct(adf["ENTRYP"])
Результаты:
ENTRYP STATUS
0 0.04 MOVEMENT_1
1 0.04 MOVEMENT_1
2 0.02 ENT_EXT1
3 0.02 ENT_EXT1
4 0.03 MOVEMENT_2
5 0.03 MOVEMENT_2
6 0.02 ENT_EXT2
7 0.01 ENT_EXT2