Commit 87ab47a0 authored by yanke's avatar yanke
Browse files

fix bug

parent b104ec49
...@@ -18,6 +18,16 @@ ...@@ -18,6 +18,16 @@
}, },
"column_add": { "column_add": {
} }
},
{
"file": "bw100.xlsx",
"sheets": [],
"column_mapping": {
},
"column_replace": {
},
"column_add": {
}
} }
] ]
} }
...@@ -17,29 +17,47 @@ args = parser.parse_args() ...@@ -17,29 +17,47 @@ args = parser.parse_args()
def fill_merged_cells(df, file_path, sheet_name): def fill_merged_cells(df, file_path, sheet_name):
"""填充合并单元格:用前一个非空值向下填充""" """填充合并单元格:用前一个非空值向下填充"""
merged_cols = set()
try: try:
wb = pd.ExcelFile(file_path).book from openpyxl import load_workbook
wb = load_workbook(file_path, data_only=True)
ws = wb[sheet_name] ws = wb[sheet_name]
merged_ranges = ws.merged_cells.ranges merged_ranges = ws.merged_cells.ranges
if not merged_ranges: if not merged_ranges:
wb.close()
return df return df
for merged_range in merged_ranges: for merged_range in merged_ranges:
min_col, min_row = merged_range.min_col, merged_range.min_row min_col, min_row = merged_range.min_col, merged_range.min_row
max_col, max_row = merged_range.max_col, merged_range.max_row max_col, max_row = merged_range.max_col, merged_range.max_row
first_cell = ws.cell(min_row, min_col).value for col_idx in range(min_col, max_col + 1):
merged_cols.add(col_idx - 1)
for row in range(min_row + 1, max_row + 1): wb.close()
for col in range(min_col, max_col + 1): except Exception as e:
ws.cell(row, col).value = first_cell print(f" 检测合并单元格失败: {e}")
return df
df = pd.read_excel(file_path, sheet_name=sheet_name, engine='openpyxl') for merged_range in merged_ranges:
except Exception: min_col, min_row = merged_range.min_col, merged_range.min_row
pass max_col, max_row = merged_range.max_col, merged_range.max_row
for col_idx in range(min_col, max_col + 1):
merged_cols.add(col_idx - 1)
wb.close(wb)
except Exception as e:
print(f" 检测合并单元格失败: {e}")
return df
if not merged_cols:
return df
for col in df.columns: for i, col in enumerate(df.columns):
if i in merged_cols:
df[col] = df[col].fillna(method='ffill') df[col] = df[col].fillna(method='ffill')
if pd.api.types.is_numeric_dtype(df[col]): if pd.api.types.is_numeric_dtype(df[col]):
col_values = df[col].dropna() col_values = df[col].dropna()
...@@ -498,7 +516,7 @@ all_metric_cols = normal_metrics + [c['column'] for c in normalize_configs] ...@@ -498,7 +516,7 @@ all_metric_cols = normal_metrics + [c['column'] for c in normalize_configs]
print(f"\n普通指标: {normal_metrics}") print(f"\n普通指标: {normal_metrics}")
print(f"归一化配置: {normalize_configs}") print(f"归一化配置: {normalize_configs}")
dist_combinations = df_renamed.groupby(dist_cols).size().reset_index() dist_combinations = df_renamed.groupby(dist_cols).size().reset_index(name='count')
print(f"\n将生成 {len(dist_combinations)} 个图表...") print(f"\n将生成 {len(dist_combinations)} 个图表...")
chart_count = 0 chart_count = 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment