"vscode:/vscode.git/clone" did not exist on "2db20a6f8218ee9c04044b5596a71ae4154d68d3"
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,37 +17,55 @@ args = parser.parse_args() ...@@ -17,37 +17,55 @@ 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)
wb.close()
except Exception as e:
print(f" 检测合并单元格失败: {e}")
return df
for merged_range in merged_ranges:
min_col, min_row = merged_range.min_col, merged_range.min_row
max_col, max_row = merged_range.max_col, merged_range.max_row
for row in range(min_row + 1, max_row + 1): for col_idx in range(min_col, max_col + 1):
for col in range(min_col, max_col + 1): merged_cols.add(col_idx - 1)
ws.cell(row, col).value = first_cell
df = pd.read_excel(file_path, sheet_name=sheet_name, engine='openpyxl') wb.close(wb)
except Exception: except Exception as e:
pass print(f" 检测合并单元格失败: {e}")
return df
if not merged_cols:
return df
for col in df.columns: for i, col in enumerate(df.columns):
df[col] = df[col].fillna(method='ffill') if i in merged_cols:
if pd.api.types.is_numeric_dtype(df[col]): df[col] = df[col].fillna(method='ffill')
col_values = df[col].dropna() if pd.api.types.is_numeric_dtype(df[col]):
if len(col_values) > 0 and col_values.apply(lambda x: float(x).is_integer() if pd.notna(x) else True).all(): col_values = df[col].dropna()
try: if len(col_values) > 0 and col_values.apply(lambda x: float(x).is_integer() if pd.notna(x) else True).all():
df[col] = df[col].astype(int) try:
except (ValueError, TypeError): df[col] = df[col].astype(int)
pass except (ValueError, TypeError):
pass
return df return df
...@@ -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