|
@@ -5,12 +5,14 @@ from pathlib import Path
|
|
|
import numpy as np
|
|
|
import pandas as pd
|
|
|
|
|
|
-from crossborder.utils.db_helper import DBHelper
|
|
|
from crossborder.utils.constants import COUNTRY_CODE_MAPPING, EXCLUDE_REGIONS, DOWNLOAD_DIR
|
|
|
-from crossborder.utils.parse_utils import clean_county_name, clean_commodity_name, convert_wan_to_yuan, \
|
|
|
- find_unmatched_countries, \
|
|
|
+from crossborder.utils.db_helper import DBHelper
|
|
|
+from crossborder.utils.log import get_logger
|
|
|
+from crossborder.utils.parse_utils import clean_county_name, clean_commodity_name, find_unmatched_countries, \
|
|
|
extract_year_month_from_path, traverse_and_process, parse_value
|
|
|
|
|
|
+log = get_logger(__name__)
|
|
|
+
|
|
|
# 常量配置(新增路径正则校验)
|
|
|
PROV_CODE = "410000"
|
|
|
PROV_NAME = "河南省"
|
|
@@ -36,9 +38,9 @@ def parse_excel(current_dir):
|
|
|
country_file = next(current_path.glob("*国别*"), None)
|
|
|
process_country_trade(country_file, year, month)
|
|
|
|
|
|
- print(f"{current_dir}数据已全部成功处理")
|
|
|
+ log.info(f"{current_dir}数据已全部成功处理")
|
|
|
except Exception as e:
|
|
|
- print(f"处理失败:{current_dir},错误:{str(e)}")
|
|
|
+ log.error(f"处理失败:{current_dir},错误:{str(e)}")
|
|
|
raise
|
|
|
|
|
|
|
|
@@ -71,7 +73,12 @@ def process_combined_trade(current_dir, year, month):
|
|
|
valid_data['prov_name'] = PROV_NAME
|
|
|
#进出口总值计算
|
|
|
valid_data['monthly_total'] = valid_data['monthly_import'].fillna(0) + valid_data['monthly_export'].fillna(0)
|
|
|
- valid_data['monthly_total'] = valid_data['monthly_total'].replace(0, np.nan)
|
|
|
+ # valid_data['monthly_total'] = valid_data['monthly_total'].replace(0, np.nan)
|
|
|
+ # 仅当两个字段均为0时转为NaN,已发布的数据有为0的存在
|
|
|
+ valid_data['monthly_total'] = valid_data['monthly_total'].mask(
|
|
|
+ (valid_data['monthly_import'].isna() & valid_data['monthly_export'].isna()),
|
|
|
+ np.nan
|
|
|
+ )
|
|
|
|
|
|
# 定义目标字段
|
|
|
target_cols = [
|