Код: Выделить всё
# Combine idast, idsui, and idwd into one column for suta (state unemployment tax)
suta_cols = ["idast", "idsui", "idwd", "id_unemployment_company", "id_workforce_dev_fund"]
existing_cols = [
c for c in suta_cols
if c in combined_2024_2025.columns
]
combined_2024_2025["suta"] = (
combined_2024_2025[existing_cols]
.fillna(0)
.sum(axis=1)
)
Код: Выделить всё
"id_unemployment_company", "id_workforce_dev_fund"
Впоследствии я попытался применить ту же логику к столбцу «гарнир» (гарн1):
Код: Выделить всё
# Combine garnishments
garn_cols = ["child_support_garnishment", "garnishment_child_support", "wage_garnishment_other", "garnishment_state_tax_levy"]
other_existing_cols = [
c for c in garn_cols
if c in combined_2024_2025.columns
]
combined_2024_2025["garn1"] = (
combined_2024_2025[other_existing_cols]
.fillna(0)
.sum(axis=1)
)
Подробнее здесь: https://stackoverflow.com/questions/798 ... ultiple-co
Мобильная версия