Оптимизируй код
%%time
# нахожу курьеров с одним типом передвижения
unique_type_couriers = raw_df.groupby(['courier_id'])['raw_courier_type'].nunique().reset_index()
unique_type_couriers = unique_type_couriers.loc[unique_type_couriers['raw_courier_type'] == 1]
unique_type_couriers = unique_type_couriers['courier_id'].values.tolist()

# выделяю только пеших и вело курьеров
# только пешие курьеры
# raw_df_pedestrian = raw_df.loc[(raw_df['courier_id'].isin(unique_type_couriers))&(raw_df['raw_courier_type'].isin(['pedestrian']))]
# только пешие заказы
raw_df_pedestrian = raw_df.loc[(raw_df['raw_courier_type'].isin(['pedestrian']))]
# raw_df_pedestrian = raw_df.loc[(raw_df['courier_type'].isin(['pedestrian']))]

raw_df_bicycle = raw_df.loc[(raw_df['courier_id'].isin(unique_type_couriers))&(raw_df['raw_courier_type'].isin(['bicycle', 'electric_bicycle']))]

# считаю средний кэф за неделю
raw_df_pedestrian['mean_courier_demand_coefficient'] = raw_df_pedestrian.groupby(['week', 'region_id'], as_index=False)['courier_demand_coefficient'].transform('mean')
raw_df_pedestrian['mean_shift_additional_coeff'] = raw_df_pedestrian.groupby(['week', 'region_id'], as_index=False)['shift_additional_coeff'].transform('mean')
raw_df_pedestrian['mean_coeff'] = raw_df_pedestrian.groupby(['week', 'region_id'], as_index=False)['coeff'].transform('mean')


raw_df_pedestrian['cpo_new_wo_coef_wo_bonus'] = raw_df_pedestrian.apply(
        lambda x: calc_cpo_new(
            x.has_pickup_flg,
            x.has_dropoff_flg,
            1,
            x.fix,
            x.per_km,
            x.distance,
            x.batch_additional_part,
            0,
            x.min_base_order_payment_retariff,
            x.in_rest_time_part,
            x.heavy_fix_part
        ),
        axis=1,
)

# рассчитываю сро со средним кэфом за неделю
raw_df_pedestrian['cpo_new_with_avg_coef'] = raw_df_pedestrian.apply(
        lambda x: calc_cpo_new(
            x.has_pickup_flg,
            x.has_dropoff_flg,
            x.mean_coeff,
            x.fix,
            x.per_km,
            x.distance,
            x.batch_additional_part,
            x.urgency_part,
            x.min_base_order_payment_retariff,
            x.in_rest_time_part,
            x.heavy_fix_part
        ),
        axis=1,
)

raw_df_pedestrian['cpo_old_with_avg_coef'] = raw_df_pedestrian.apply(
        lambda x: calc_cpo_old(
            x.mean_coeff,
            x.fix_old,
            x.per_km_old,
            x.distance
        ),
        axis=1,
)

# рассчитываю сро без кэпа
raw_df_pedestrian['cpo_new_wo_cap'] = raw_df_pedestrian.apply(
        lambda x: calc_cpo_wo_cap_new(
            x.has_pickup_flg,
            x.has_dropoff_flg,
            (x.courier_demand_coefficient + x.shift_additional_coeff),
            x.fix,
            x.per_km,
            x.distance,
            x.batch_additional_part,
            x.urgency_part,
            x.in_rest_time_part,
            x.heavy_fix_part
        ),
        axis=1,
)

raw_df_pedestrian['cpo_new_wo_cap_wo_coef'] = raw_df_pedestrian.apply(
        lambda x: calc_cpo_wo_cap_new(
            x.has_pickup_flg,
            x.has_dropoff_flg,
            1,
            x.fix,
            x.per_km,
            x.distance,
            x.batch_additional_part,
            x.urgency_part,
            x.in_rest_time_part,
            x.heavy_fix_part
        ),
        axis=1,
)

# объединяю старый и новый сро,мпю в одно поле
retariff_mln = '2024-08-26'
retariff_nino = '2024-08-19'
retariff_msc = '2024-09-09'

cond_list = [
    (raw_df_pedestrian['region_id'] == 27) & (raw_df_pedestrian['dt'] < retariff_mln), 
    (raw_df_pedestrian['region_id'] == 17) & (raw_df_pedestrian['dt'] < retariff_nino),
    (raw_df_pedestrian['region_id'] == 1) & (raw_df_pedestrian['dt'] < retariff_msc),
    (raw_df_pedestrian['region_id'] == 3) & (raw_df_pedestrian['dt'] < retariff_msc)
]

choice_list_mpu = [
    raw_df_pedestrian['mpu_old'],
    raw_df_pedestrian['mpu_old'],
    raw_df_pedestrian['mpu_old'],
    raw_df_pedestrian['mpu_old']
]
default_mpu = raw_df_pedestrian['mpu_new']

choice_list_mpu_wo_coeff = [
    raw_df_pedestrian['mpu_wo_coef_old'],
    raw_df_pedestrian['mpu_wo_coef_old'],
    raw_df_pedestrian['mpu_wo_coef_old'],
    raw_df_pedestrian['mpu_wo_coef_old']
] 
default_mpu_wo_coef = raw_df_pedestrian['mpu_wo_coef_new']

choice_list_cpo = [
    raw_df_pedestrian['cpo_old'],
    raw_df_pedestrian['cpo_old'],
    raw_df_pedestrian['cpo_old'],
    raw_df_pedestrian['cpo_old']
]
default_cpo = raw_df_pedestrian['cpo_new']

choice_list_cpo_wo_coeff = [
    raw_df_pedestrian['cpo_wo_coef_old'],
    raw_df_pedestrian['cpo_wo_coef_old'],
    raw_df_pedestrian['cpo_wo_coef_old'],
    raw_df_pedestrian['cpo_wo_coef_old']
] 
default_cpo_wo_coef = raw_df_pedestrian['cpo_wo_coef_new']

choice_list_cpo_wo_coeff_wo_bonus = [
    raw_df_pedestrian['cpo_wo_coef_old'],
    raw_df_pedestrian['cpo_wo_coef_old'],
    raw_df_pedestrian['cpo_wo_coef_old'],
    raw_df_pedestrian['cpo_wo_coef_old']
] 
default_cpo_wo_coef_wo_bonus = raw_df_pedestrian['cpo_new_wo_coef_wo_bonus']

choice_list_cpo_with_avg_coef = [
    raw_df_pedestrian['cpo_old_with_avg_coef'],
    raw_df_pedestrian['cpo_old_with_avg_coef'],
    raw_df_pedestrian['cpo_old_with_avg_coef'],
    raw_df_pedestrian['cpo_old_with_avg_coef']
] 
default_cpo_with_avg_coef = raw_df_pedestrian['cpo_new_with_avg_coef']

choice_list_cpo_wo_cap = [
    raw_df_pedestrian['cpo_old'],
    raw_df_pedestrian['cpo_old'],
    raw_df_pedestrian['cpo_old'],
    raw_df_pedestrian['cpo_old']
] 
default_cpo_wo_cap = raw_df_pedestrian['cpo_new_wo_cap']

choice_list_cpo_wo_cap_wo_coef = [
    raw_df_pedestrian['cpo_wo_coef_old'],
    raw_df_pedestrian['cpo_wo_coef_old'],
    raw_df_pedestrian['cpo_wo_coef_old'],
    raw_df_pedestrian['cpo_wo_coef_old']
] 
default_cpo_wo_cap_wo_coef = raw_df_pedestrian['cpo_new_wo_cap_wo_coef']


raw_df_pedestrian['mpu'] = np.select(cond_list, choice_list_mpu, default_mpu)
raw_df_pedestrian['mpu_wo_coef'] = np.select(cond_list, choice_list_mpu_wo_coeff, default_mpu_wo_coef)

raw_df_pedestrian['cpo'] = np.select(cond_list, choice_list_cpo, default_cpo)
raw_df_pedestrian['cpo_wo_coef'] = np.select(cond_list, choice_list_cpo_wo_coeff, default_cpo_wo_coef)

raw_df_pedestrian['cpo_wo_coef_wo_bonus'] = np.select(cond_list, choice_list_cpo_wo_coeff_wo_bonus, default_cpo_wo_coef_wo_bonus)
raw_df_pedestrian['mpu_wo_coef_wo_bonus'] = raw_df_pedestrian['cpo_wo_coef_wo_bonus'] / (raw_df_pedestrian['cour_cte'] / 60)

raw_df_pedestrian['cpo_with_avg_coef'] = np.select(cond_list, choice_list_cpo_with_avg_coef, default_cpo_with_avg_coef)
raw_df_pedestrian['mpu_with_avg_coef'] = raw_df_pedestrian['cpo_with_avg_coef'] / (raw_df_pedestrian['cour_cte'] / 60)

raw_df_pedestrian['cpo_wo_cap'] = np.select(cond_list, choice_list_cpo_wo_cap, default_cpo_wo_cap)
raw_df_pedestrian['mpu_wo_cap'] = raw_df_pedestrian['cpo_wo_cap'] / (raw_df_pedestrian['cour_cte'] / 60)

raw_df_pedestrian['cpo_wo_cap_wo_coef'] = np.select(cond_list, choice_list_cpo_wo_cap_wo_coef, default_cpo_wo_cap_wo_coef)
raw_df_pedestrian['mpu_wo_cap_wo_coef'] = raw_df_pedestrian['cpo_wo_cap_wo_coef'] / (raw_df_pedestrian['cour_cte'] / 60)