|
@@ -45,10 +45,12 @@ def read_csv_with_header(file_path: str, header_row: int = 1, encoding: str = No
|
|
|
data = read_csv(file_path, encoding)
|
|
data = read_csv(file_path, encoding)
|
|
|
|
|
|
|
|
if not data:
|
|
if not data:
|
|
|
|
|
+ logger.error("读取的文件为空")
|
|
|
raise ValueError("读取的文件为空")
|
|
raise ValueError("读取的文件为空")
|
|
|
|
|
|
|
|
# 确保header_row在有效范围内
|
|
# 确保header_row在有效范围内
|
|
|
if header_row >= len(data):
|
|
if header_row >= len(data):
|
|
|
|
|
+ logger.error(f"标题行 {header_row} 超出文件范围")
|
|
|
raise ValueError(f"标题行 {header_row} 超出文件范围")
|
|
raise ValueError(f"标题行 {header_row} 超出文件范围")
|
|
|
|
|
|
|
|
# 使用指定行作为列名,前面的行丢弃
|
|
# 使用指定行作为列名,前面的行丢弃
|
|
@@ -75,6 +77,7 @@ def extract_column_data(df: pd.DataFrame, column_identifier: Union[str, int], st
|
|
|
"""
|
|
"""
|
|
|
try:
|
|
try:
|
|
|
if df.empty:
|
|
if df.empty:
|
|
|
|
|
+ logger.error("DataFrame为空")
|
|
|
return pd.Series()
|
|
return pd.Series()
|
|
|
|
|
|
|
|
# 处理列号或列名或列字母
|
|
# 处理列号或列名或列字母
|
|
@@ -82,15 +85,18 @@ def extract_column_data(df: pd.DataFrame, column_identifier: Union[str, int], st
|
|
|
column_identifier = column_letter_to_index(column_identifier)
|
|
column_identifier = column_letter_to_index(column_identifier)
|
|
|
if isinstance(column_identifier, int):
|
|
if isinstance(column_identifier, int):
|
|
|
if column_identifier < 0 or column_identifier >= len(df.columns):
|
|
if column_identifier < 0 or column_identifier >= len(df.columns):
|
|
|
|
|
+ logger.error(f"列号 {column_identifier} 超出范围")
|
|
|
raise ValueError(f"列号 {column_identifier} 超出范围")
|
|
raise ValueError(f"列号 {column_identifier} 超出范围")
|
|
|
column_identifier = df.columns[column_identifier]
|
|
column_identifier = df.columns[column_identifier]
|
|
|
|
|
|
|
|
# 确保列名存在
|
|
# 确保列名存在
|
|
|
if column_identifier not in df.columns:
|
|
if column_identifier not in df.columns:
|
|
|
|
|
+ logger.error(f"列名 {column_identifier} 不存在")
|
|
|
raise ValueError(f"列名 {column_identifier} 不存在")
|
|
raise ValueError(f"列名 {column_identifier} 不存在")
|
|
|
|
|
|
|
|
# 确保开始行在有效范围内
|
|
# 确保开始行在有效范围内
|
|
|
if start_row >= len(df) or start_row < 0:
|
|
if start_row >= len(df) or start_row < 0:
|
|
|
|
|
+ logger.error(f"开始行 {start_row} 超出范围")
|
|
|
raise ValueError(f"开始行 {start_row} 超出范围")
|
|
raise ValueError(f"开始行 {start_row} 超出范围")
|
|
|
|
|
|
|
|
# 提取指定列的数据
|
|
# 提取指定列的数据
|