у меня есть два цикла которые можно объединить в один. напиши код сохраняя логику и закомментированный код, который объединяет в один цикл все
# по стратегиям
general_strategies_LT = pd.DataFrame()
request_strategies = request.strategy_param_code.dropna().unique()
conn = psycopg2.connect(dbname='spr', user='user', password='passqord', host='10.1',port='614')
cursor = conn.cursor()
cursor.execute(f'''
        SELECT DISTINCT STRATEGY_ID FROM CALCULATIONS_ADMIN.EXECUTED_STRATEGY 
        WHERE date_exec BETWEEN '{date_start}' AND '{date_end}'
        AND chain_id in ('{"', '".join(good_deals)}')
        ''')
# AND chain_id in ('{"', '".join(good_deals)}')
data_strategies = [model[0] for model in list(cursor.fetchall())]
 
for strategy in tqdm(request_strategies):
    strategy_name = ''
    for data_strategy in data_strategies:
        if strategy in data_strategy:
            strategy_name = data_strategy

            request_params_steps = request[request['strategy_param_code'] == strategy]
            request_steps = set(request_params_steps.strategy_step_param_code.dropna())
            if request_steps in {'inputRequest', 'outputParams'}:
                cursor.execute(f'''
                SELECT S.chain_id, S.date_exec, S.STRATEGY_ID
                ,S.{",S.".join(list(request_params_steps['params_type'].dropna().unique()))}
                JOIN CALCULATIONS_ADMIN.EXECUTED_STRATEGY S
                WHERE (S.STRATEGY_ID='{strategy_name}' AND S.date_exec BETWEEN '{date_start}' AND '{date_end}'
                AND S.rs_code = 0 
                AND S.chain_id in ('{"', '".join(good_deals)}')
                )''')
#                 AND S.chain_id in ('{"', '".join(good_deals)}')
                
                data = cursor.fetchall()
                columns = [description[0] for description in cursor.description]
                
        #         если прогон дополнялся (или ручные запуски)
#                 cursor.execute(f'''
#                 SELECT S.chain_id, S.date_exec, S.STRATEGY_ID
#                 ,S.{",S.".join(list(request_params_steps['params_type'].dropna().unique()))}
#                 JOIN CALCULATIONS_ADMIN.EXECUTED_STRATEGY_M S
#                 WHERE (S.STRATEGY_ID='{strategy_name}' AND S.date_exec BETWEEN '{date_start}' AND '{date_end}'
#                 AND S.rs_code = 0 
#                 AND S.chain_id in ('{"', '".join(good_deals)}')
#                 )''')
#                 data1 = cursor.fetchall()
#                 data.extend(data1)
                
                df = pd.DataFrame(data, columns=columns)
                df = df.set_index('chain_id')
                general_strategies_LT = pd.concat([general_strategies_LT, df])
            else:
                for step in list(request_steps):
                    request_params_types = request[request['strategy_step_param_code'] == step]
                    request_types = list(request_params_types.params_type.dropna().unique())
                    cursor.execute(f'''
                    SELECT S.chain_id, S.date_exec, ST.step_business_id, S.STRATEGY_ID
                    ,ST.{",ST.".join(request_types)}
                    FROM CALCULATIONS_ADMIN.STRATEGY_STEP ST
                    JOIN CALCULATIONS_ADMIN.EXECUTED_STRATEGY S ON ST.executed_strategy_id = S.rq_uid
                    WHERE (S.STRATEGY_ID='{strategy_name}' AND S.date_exec BETWEEN '{date_start}' AND '{date_end}'
                    AND S.rs_code = 0 AND ST.step_business_id = '{step}'
                    AND S.chain_id in ('{"', '".join(good_deals)}')
                    )''')
    #                 AND S.chain_id in ('{"', '".join(good_deals)}')

                    data = cursor.fetchall()
                    columns = [description[0] for description in cursor.description]

            #         если прогон дополнялся (или ручные запуски)
    #                 cursor.execute(f'''
    #                 SELECT S.chain_id, S.date_exec, ST.step_business_id, S.STRATEGY_ID
    #                 ,ST.{",ST.".join(request_types)}
    #                 FROM CALCULATIONS_ADMIN.STRATEGY_STEP_M ST
    #                 JOIN CALCULATIONS_ADMIN.EXECUTED_STRATEGY_M S ON ST.executed_strategy_id = S.rq_uid
    #                 WHERE (S.STRATEGY_ID='{strategy_name}' AND S.date_exec BETWEEN '{date_start}' AND '{date_end}'
    #                 AND S.rs_code = 0 AND ST.step_business_id = '{step}'
    #                 AND chain_id in ('{"', '".join(good_deals)}')
    #                 )''')
    #                 data1 = cursor.fetchall()
    #                 data.extend(data1)

                    df = pd.DataFrame(data, columns=columns)
                    df = df.set_index('chain_id')
                    general_strategies_LT = pd.concat([general_strategies_LT, df])
            
    if not strategy_name:
        print(f'Стратегия {strategy} не найдена')
        continue
        
general_strategies_LT.sort_values(by='date_exec', inplace=True)
        
cursor.close()
conn.close()
strategies = pd.DataFrame(index=general_strategies_LT.index.unique())
repeated_strategies = []
for strategy in tqdm(request_strategies):
    strategy_name = ''
    for data_strategy in data_strategies:
        if strategy in data_strategy:
            strategy_name = data_strategy
    
            request_params_steps = request[request['strategy_param_code'] == strategy]
            request_steps = set(request_params_steps.strategy_step_param_code.dropna())
            if request_steps in {'inputRequest', 'outputParams'}:
                request_params = request_params_steps[request_params_steps['strategy_param_code'] == strategy]
                df_step = general_strategies_LT[general_strategies_LT['strategy_id'] == strategy_name][['in_params', 'out_params']]
                if strategy in repeated_strategies:
                    df_step.columns = ['in_params' + '_' + strategy_name.split(' ')[0] + '_' + str(repeated_strategies.count(strategy)), 'out_params' + '_' + strategy_name.split(' ')[0] + '_' + '_' + str(repeated_strategies.count(strategy))]
                else:
                    df_step.columns = ['in_params' + '_' + strategy_name.split(' ')[0], 'out_params' + '_' + strategy_name.split(' ')[0]]
                for col in df_step.columns:
                    if df_step[col].isna().sum() == len(df_step):
                        df_step.drop(columns=col, inplace=True)
                strategies = strategies.join(df_step, how='outer')
            
            
            if request_steps:
                for step in tqdm(request_steps):
                    request_params = request_params_steps[request_params_steps['strategy_step_param_code'] == step]
                    df_step = general_strategies_LT[general_strategies_LT['step_business_id'] == step][['in_params', 'out_params']]
                    if strategy in repeated_strategies:
                        df_step.columns = ['in_params' + '_' + strategy_name.split(' ')[0] + '_' + step + '_' + str(repeated_strategies.count(strategy)), 'out_params' + '_' + strategy_name.split(' ')[0] + '_' + step + '_' + str(repeated_strategies.count(strategy))]
                    else:
                        df_step.columns = ['in_params' + '_' + strategy_name.split(' ')[0] + '_' + step, 'out_params' + '_' + strategy_name.split(' ')[0] + '_' + step]
                    for col in df_step.columns:
                        if df_step[col].isna().sum() == len(df_step):
                            df_step.drop(columns=col, inplace=True)
                    strategies = strategies.join(df_step, how='outer')

            repeated_strategies.append(strategy)
    
    if not strategy_name:
        print(f'Стратегия {strategy} не найдена')
        continue
        
unique_strategy_ids = general_strategies_LT.groupby(general_strategies_LT.index)['strategy_id'].unique().to_frame()
unique_strategy_ids['strategy_ids'] = unique_strategy_ids['strategy_id'].apply(lambda x: '|| '.join(map(str, x)))
unique_strategy_ids = unique_strategy_ids.drop('strategy_id', axis=1)
strategies = strategies.join(unique_strategy_ids, how='left')