This commit is contained in:
2026-11-24 07:53:07 +01:00
parent 6f1844dbb8
commit 8866de03cd
8 changed files with 213 additions and 14 deletions
+10 -2
View File
@@ -42,6 +42,13 @@ def load(pattern):
frames = []
for path in glob.glob(pattern):
d = pd.read_csv(path, parse_dates=["date"])[["date", "positive", "negative"]].copy()
if d.empty:
print(f"skipping {path}: no rows")
continue
full = pd.date_range(d["date"].min(), d["date"].max(), freq="D")
d = (d.groupby("date")[["positive", "negative"]].sum()
.reindex(full, fill_value=0)
.rename_axis("date").reset_index())
d["sheet"] = os.path.splitext(os.path.basename(path))[0]
frames.append(d)
if not frames:
@@ -50,11 +57,12 @@ def load(pattern):
print(len(frames), "files loaded,", df["sheet"].nunique(), "games")
return df
def add_groups(df):
"""Attach MP_i from the tag file; drop games tagged both or missing from the file."""
tags = pd.read_csv(TAGS_FILE)[["sheet", "group"]].drop_duplicates("sheet")
tags = pd.read_csv(TAGS_FILE, dtype={"sheet": str})[["sheet", "group"]].drop_duplicates("sheet")
tags["sheet"] = tags["sheet"].str.strip()
tags["group"] = tags["group"].astype(str).str.strip().str.lower()
df["sheet"] = df["sheet"].astype(str)
df = df.merge(tags, on="sheet", how="left")
print("Games per group:", df.groupby("group")["sheet"].nunique().to_dict())
missing = df.loc[df["group"].isna(), "sheet"].nunique()