feat: add --value-col param to inject for multi-column CSV support
This commit is contained in:
@@ -4,11 +4,12 @@ from pathlib import Path
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def read_csv(path: str | Path) -> tuple[list[int], list[float], list[int]]:
|
||||
def read_csv(path: str | Path, value_col: str = "value") -> tuple[list[int], list[float], list[int]]:
|
||||
"""读 timestamp,value,label CSV 文件。
|
||||
|
||||
Args:
|
||||
path: CSV 文件路径
|
||||
value_col: 数值列名 (default: "value")
|
||||
|
||||
Returns:
|
||||
(timestamps_ms, values, labels) 三元组
|
||||
@@ -22,13 +23,13 @@ def read_csv(path: str | Path) -> tuple[list[int], list[float], list[int]]:
|
||||
"""
|
||||
df = pd.read_csv(path)
|
||||
|
||||
if "timestamp" not in df.columns or "value" not in df.columns:
|
||||
raise ValueError(f"CSV 缺少 timestamp 或 value 列: {path}")
|
||||
if "timestamp" not in df.columns or value_col not in df.columns:
|
||||
raise ValueError(f"CSV 缺少 timestamp 或 {value_col} 列: {path}")
|
||||
|
||||
timestamps = pd.to_datetime(df["timestamp"])
|
||||
timestamps_ms = (timestamps.astype("int64") // 10**6).tolist()
|
||||
|
||||
values = df["value"].astype(float).tolist()
|
||||
values = df[value_col].astype(float).tolist()
|
||||
|
||||
labels = df["label"].fillna(0).astype(int).tolist() if "label" in df.columns else [0] * len(df)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user