72 skip_downloaded_files: bool = False) -> None:
73 """
74 Склеивает все .csv файлы в папке в один
75
76 Args:
77 folder_name (str): имя папки с .csv файлами
78 combined_file_name (str): имя склеенного .csv файла
79 logger_label (str, optional): текст заголовка для логирования. Defaults to "ChEMBL__combine".
80 print_to_console (bool, optional): нужно ли выводить логирование в консоль. Defaults to False.
81 """
82
83 UpdateLoggerFormat(logger_label, "fg #474747")
84
85 logger.info(f"Start combining all downloads...".ljust(77))
86 logger.info(f"{'-' * 77}")
87
88 if IsFileInFolder(folder_name, f"{combined_file_name}.csv") and skip_downloaded_files:
89 logger.warning(
90 f"File '{combined_file_name}' is in folder, no need to combine".ljust(77))
91 return
92
93 combined_df = pd.DataFrame()
94
95 for file_name in os.listdir(folder_name):
96 if file_name.endswith('.csv') and file_name != f"{combined_file_name}.csv":
97
98 if print_to_console:
99 logger.info(f"Opening '{file_name}'...".ljust(77))
100
101 full_file_name: str = os.path.join(folder_name, file_name)
102
103 if print_to_console:
104 logger.success(f"Opening '{file_name}': SUCCESS".ljust(77))
105
106 logger.info(
107 f"Collecting '{file_name}' to pandas.DataFrame()...".ljust(77))
108 try:
109 df = pd.read_csv(full_file_name, sep=';', low_memory=False)
110
111 if print_to_console:
112 logger.success(
113 f"Collecting '{file_name}' to pandas.DataFrame(): SUCCESS".ljust(77))
114
115 logger.info(
116 f"Concatenating '{file_name}' to combined_data_frame...".ljust(77))
117
118 combined_df = pd.concat([combined_df, df], ignore_index=True)
119
120 if print_to_console:
121 logger.success(
122 f"Concatenating '{file_name}' to combined_data_frame: SUCCESS".ljust(77))
123
124 except Exception as exception:
125 PrintException(exception, logger_label, "fg #474747")
126
127 if print_to_console:
128 logger.info(f"{'-' * 77}")
129
130 logger.info(
131 f"Collecting to combined .csv file in '{folder_name}'...".ljust(77))
132 try:
133 combined_df.to_csv(
134 f"{folder_name}/{combined_file_name}.csv", sep=';', index=False)
135 logger.success(
136 f"Collecting to combined .csv file in '{folder_name}': SUCCESS".ljust(77))
137
138 except Exception as exception:
139 PrintException(exception, logger_label, "fg #474747")
140
141 logger.info(f"{'-' * 77}")
142 logger.success(f"End combining all downloads".ljust(77))
143
144