Commit 19bae038 by zhouhaibao

fix(data-process): 修复数据处理中的汇总行错误填充问题

- 在前向填充前保存原始空值标记,防止汇总行被错误填充
- 添加过滤逻辑移除ffill错误填充的汇总行数据
- 优化市场费列查找逻辑,排除比率类列的干扰
- 增加数据过滤日志记录便于调试追踪
1 parent 92a2e971
......@@ -1599,7 +1599,9 @@ class DataProcessor:
category_nonnull_before = df[col_category].notna().sum()
# 前向填充合并单元格的值(流量方、车型、商品类型列都可能有合并单元格)
# 先保存原始空值标记(用于过滤末尾汇总行,防止 ffill 将汇总行错误填充)
if col_flow:
original_flow_empty_mask = df[col_flow].isna() | (df[col_flow].astype(str).str.strip() == '')
df[col_flow] = df[col_flow].ffill()
if col_model:
df[col_model] = df[col_model].ffill()
......@@ -1640,6 +1642,15 @@ class DataProcessor:
elif visible_indices is None:
logger.warning(f"[市场费诊断] Sheet '{sheet_name}': get_visible_row_indices 返回 None,使用所有行")
# 过滤 ffill 前原始流量方为空的行(汇总行/合计行被 ffill 错误填充导致的幽灵行)
if col_flow:
original_row_count = len(df)
valid_mask = ~original_flow_empty_mask.reindex(df.index)
df = df[valid_mask]
filtered_count = original_row_count - len(df)
if filtered_count > 0:
logger.info(f"[市场费] Sheet '{sheet_name}': 过滤原始空行 {filtered_count} 条(ffill填充的汇总行),剩余 {len(df)} 行")
# 调试日志:显示所有列名
logger.info(f"[市场费] Sheet '{sheet_name}' 共 {len(df.columns)} 列: {list(df.columns)}")
logger.info(f"[市场费] 数据行数: {len(df)}")
......@@ -1657,10 +1668,12 @@ class DataProcessor:
# 根据配置选择取费列
if fee_col_type == 'market_fee':
col_fee = col_fee_market
# 如果没找到"市场费"列,尝试找包含"市场费"的列
# 如果没找到"市场费"列,尝试找包含"市场费"的列(排除比率类列)
if not col_fee:
for col in df.columns:
if '市场费' in str(col) and '总额' not in str(col) and '合计' not in str(col):
col_str = str(col)
if '市场费' in col_str and '总额' not in col_str and '合计' not in col_str \
and '比例' not in col_str and '比率' not in col_str and '占比' not in col_str:
col_fee = col
break
else: # 'market_fee_total'
......@@ -1668,7 +1681,9 @@ class DataProcessor:
# 如果没找到"市场费总额"列,尝试找包含"总额"或"合计"的列
if not col_fee:
for col in df.columns:
if '总额' in str(col) or '合计' in str(col):
col_str = str(col)
if ('总额' in col_str or '合计' in col_str) \
and '比例' not in col_str and '比率' not in col_str:
col_fee = col
break
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!