Вернуть id из фрейма после проверки
# Получаю список статусов
get_data_from_first_table = """
SELECT id,pas_id, date_add, status_id
FROM table_1
where status_id !=7
and date_add>= now()- interval '10 day'
order by date_add asc limit 50"""
cur.execute(get_data_from_first_table)
data_frame_from_first_table = cur.fetchall()
# преобразую в фрейм, группируя по pas_id
data_frame_from_first_table_to_frame = pd.DataFrame(data_frame_from_first_table, columns=['id','pas_id','date_add','status_id'])
# преобразую статусы в список
status_from_frame_to_list = data_frame_from_first_table_to_frame.groupby('pas_id').agg(tuple)['status_id'].to_list()
############################
pas_id
32250224 (3,)
34045553 (0, 1)
34045587 (0, 0, 1, 2, 3)
34045664 (0, 1, 3)
34045701 (0, 1)
34045735 (1,)
############################
# получаю в качестве списка кортежей допустимые пары значений
d_to_list =list(dict_of_right_transitions.keys()) # [(0, 1), (0, 2), (0, 6), (1, 2), (1, 3), (1, 4), (1, 5)]
# если элемент один то добавляю элемент 666 и разбиваю исходный список статусов на пары для последующей проверки
# исходный [(3,), (0, 1), (0, 0, 1, 2, 3), (0, 1, 3), (0, 1), (1,), (10,)]
def appendToOneStatusInList(statusfromframe_tolist):
resultStatus = []
for cort in statusfromframe_tolist:
resultStatus.append(list((zip(cort, cort[1:] or (666,)))))
return resultStatus
# после преобразования [[(3, 666)], [(0, 1)], [(0, 0), (0, 1), (1, 2), (2, 3)], [(0, 1), (1, 3)], [(0, 1)], [(1, 666)], [(10, 666)]]
#поиск несоответсвия между порлученным списком и словарем допустимых переходов из статсуса в статус
def check(listOfstatus):
testListWithErrorStatus = []
for item in listOfstatus:
for i in item:
if i not in d_to_list:
testListWithErrorStatus.append(item)
print(Fore.YELLOW + '\n', 'Errors in :', i , 'from', item, '\n')
else:
pass
return testListWithErrorStatus
И вот дальше мне нужно получить те статусы, которые не подходят к списку допустимых статусов, и получить их id в фрейме