MCPcopy Index your code
hub / github.com/KnowledgeXLab/LeanRAG / write_csv

Function write_csv

tools/io_file.py:489–506  ·  view source on GitHub ↗

写入CSV文件,支持多线程处理。 参数: - file_path (str): 文件路径。 - data (DataFrame): 要写入的CSV数据。 - mode (str): 写入模式,默认为 'a'(追加模式),可以选择 'w'(覆盖模式)。 - chunk_size (int): 当数据量较大时,使用多线程写入,单位为字节。 - encoding (str): 写入文件的编码格式,默认为 'utf-8'。

(file_path, data, mode, chunk_size, encoding='utf-8')

Source from the content-addressed store, hash-verified

487
488
489def write_csv(file_path, data, mode, chunk_size, encoding='utf-8'):
490 """
491 写入CSV文件,支持多线程处理。
492
493 参数:
494 - file_path (str): 文件路径。
495 - data (DataFrame): 要写入的CSV数据。
496 - mode (str): 写入模式,默认为 'a'(追加模式),可以选择 'w'(覆盖模式)。
497 - chunk_size (int): 当数据量较大时,使用多线程写入,单位为字节。
498 - encoding (str): 写入文件的编码格式,默认为 'utf-8'
499 """
500 data_size = data.memory_usage(index=True).sum() # 计算DataFrame的大小
501 if data_size > chunk_size:
502 logger.info(f"数据较大,启用多线程写入")
503 write_csv_multithread(file_path, data, mode, chunk_size, encoding)
504 else:
505 logger.info(f"写入CSV文件: {file_path}")
506 data.to_csv(file_path, mode=mode, encoding=encoding, index=False)
507
508
509def write_csv_multithread(file_path, data, mode, chunk_size, encoding='utf-8'):

Callers 1

writeFunction · 0.85

Calls 1

write_csv_multithreadFunction · 0.85

Tested by

no test coverage detected