소스 검색

fix: correct column header insertion in insert_column method

mrh (aider) 1 년 전
부모
커밋
670d09c62b
1개의 변경된 파일8개의 추가작업 그리고 7개의 파일을 삭제
  1. 8 7
      function_calling/excel_processor.py

+ 8 - 7
function_calling/excel_processor.py

@@ -183,12 +183,6 @@ class ExcelProcessor:
             
             
         Returns:
         Returns:
             pd.DataFrame: 包含新列的DataFrame
             pd.DataFrame: 包含新列的DataFrame
-        
-        example:
-            processor.insert_column('B', '翻译结果')
-            ref_column_list = [match[1] for match in matches]
-            for ref_column in ref_column_list:
-                processor.insert_column(ref_column, '翻译结果')
         """
         """
         df = self.df
         df = self.df
         try:
         try:
@@ -206,7 +200,14 @@ class ExcelProcessor:
             # 插入新列
             # 插入新列
             df.insert(insert_index, new_column_name, '')
             df.insert(insert_index, new_column_name, '')
             
             
-            logger.info(f"成功在列 '{ref_column}' 的 '{position}' 插入新列 '{new_column_name}' ")
+            # 调整表头行数据
+            if self.header_row > 0:
+                # 将新列的表头行设置为空
+                df.iloc[:self.header_row, insert_index] = ''
+                # 在表头行设置新列名
+                df.iloc[self.header_row, insert_index] = new_column_name
+            
+            logger.info(f"成功在列 '{ref_column}' 的 '{position}' 插入新列 '{new_column_name}'")
             return df
             return df
             
             
         except Exception as e:
         except Exception as e: