读取CSV文件。 参数: - file_path (str): 文件路径。 - chunk_size (int): 当文件大于此大小时,使用多线程读取。 - encoding (str): 文件编码格式,默认为 'utf-8'。 返回: - DataFrame: 读取的CSV文件内容。
(file_path, chunk_size, encoding='utf-8')
| 167 | |
| 168 | |
| 169 | def read_csv(file_path, chunk_size, encoding='utf-8'): |
| 170 | """ |
| 171 | 读取CSV文件。 |
| 172 | |
| 173 | 参数: |
| 174 | - file_path (str): 文件路径。 |
| 175 | - chunk_size (int): 当文件大于此大小时,使用多线程读取。 |
| 176 | - encoding (str): 文件编码格式,默认为 'utf-8'。 |
| 177 | |
| 178 | 返回: |
| 179 | - DataFrame: 读取的CSV文件内容。 |
| 180 | """ |
| 181 | file_size = os.path.getsize(file_path) |
| 182 | if file_size > chunk_size: |
| 183 | logger.info(f"文件 {file_path} 较大,启用多线程读取") |
| 184 | return read_csv_multithread(file_path, chunk_size, encoding) |
| 185 | else: |
| 186 | logger.info(f"读取CSV文件: {file_path}") |
| 187 | return pd.read_csv(file_path, encoding=encoding) |
| 188 | |
| 189 | |
| 190 | def read_csv_multithread(file_path, chunk_size, encoding='utf-8'): |
no test coverage detected