Project Details

macros.py funtion macrodias()

June 6th 2023

"Using the datetime library, I get the current date in the format ""yyyy-mm-dd"". Using the os library, the dynamic path for the ""Pendientes2.xlsx"" and ""Festivos.xlsx"" file is generated Then, using the Pandas library, the files are read and the dates are reformatted to 'dd/mm/yyyy'. First, this change is applied in the 'HOLIDAYS' column of the ""Festivos.xlsx"" file and then in the 'Date of Issue' column of the ""Pendientes2.xlsx"" file, using the 'to_datetime' function of Pandas. A list of dates from the ""Festivos.xlsx"" file is then created. Next, a function is defined within the 'calcular_dias_laborables' function, which is designed to determine the number of working days between two dates, excluding the holidays provided in the 'festivos_list' list. This function uses a 'while' loop to iterate over each day between 'fecha_inicio' and 'fecha_fin'. In each iteration, check to see if the day of the week of the current date is a working day (Monday through Friday) and if the date is not present in the holiday list. If both conditions are met, the 'dias_laborables' counter is incremented. In the end, the function returns the total number of working days found. Subsequently, Pandas' 'apply' function is used to apply a custom function to each row in the 'df_pend3' DataFrame. The custom function is specified by a lambda expression that takes the current row of the DataFrame as input and calculates the working days between the date of shipment of that row (column ""Date Shipped"") and a given current date, using the 'calcular_dias_laborables' function. The result of this operation is assigned to a new column named ""Days"" in the 'df_pend3' DataFrame. Finally, the DataFrame is sorted by 'Authorization Number' and the result is saved in an Excel file called ""Pendientes3.xlsx"". Finally, the function returns a value of 2 if executed successfully. Otherwise, it returns the error line along with an explanatory message of the error." library: sys, pandas, datetime, os, openpyxl

macros.py funtion macrodias()