i'm having problems getting the correct result from the “calculated_value_m1” def that calls the defs above, how can i solve it? def calc_objetivo_c(row): temp_prod = row.get("Temp Prod", 0) qtd = row.get("qtdPares", 0) data = row.get("data1", None) if pd.isna(data) or temp_prod == 0: logging.warning(f"Missing data or Temp Prod is zero: {row}") return 0 python_weekday = data.weekday() dax_weekday = ((python_weekday + 1) % 7) + 1 if dax_weekday in [2, 3, 4, 5, 6]: result = qtd / (1 - (7.5 - temp_prod) / 7.5) elif dax_weekday == 7 and qtd != 0: result = qtd / (1 - (5.75 - temp_prod) / 5.75) return result call a def to read manual objective in excel: def objetivo_manual(excel_path): try: df_obj = pd.read_excel(excel_path, sheet_name="Objetivos") return df_obj except Exception as e: logging.error(f"Failed to load Excel file: {e}") return pd.DataFrame() def objetivo(row, calc_objetivo_c, objetivo_manual): obj_manual = objetivo_manual(excel_path) if obj_manual.empty: return calc_objetivo_c(row) else: logging.info(f"Using manual objetivo: {obj_manual}") return obj_manual.iloc[0, 0] In this part, if I don't have data (int) to display in excel, I want it to calculate “calc_objective_c” together with sum = 0 for _, trab in dff.iterrows def valor_calculado_m1(row, df_ntrab, objetivo): data_prod = row.get("data1", None) if pd.isna(data_prod): return 0 data_date = data_prod.date() linha = row.get("Linha", "") dff = df_ntrab[ (df_ntrab["Linha"] == linha) & (df_ntrab["Data"] == data_date) ] if dff.empty: return 0 soma = 0 for _, trab in dff.iterrows(): n = trab["NTrab"] if n >= 15: soma += objetivo * n / 15 else: soma += objetivo * n / 12 return soma another on page: m1.py dff["valor_objetivo"] = dff.apply( lambda row: objetivo(row, calc_objetivo_c, objetivo_manual), axis=1 ) dff["objetivo-c"] = dff.apply( lambda row: valor_calculado_m1(row, df_ntrab, row["valor_objetivo"]), axis=1 ) valor_calc_m1_total = dff["objetivo-c"].sum() Continue reading...