Standardize formatting with black and apply ruff auto-fixes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""
|
|
Script to undo PO -> pickoffs rename for position player defense files.
|
|
Keeps the rename for defense_p.csv (pitchers).
|
|
"""
|
|
|
|
import pandas as pd
|
|
import os
|
|
|
|
# Directory with defense files
|
|
DATA_DIR = "data-input/2005 Live Cardset/"
|
|
|
|
# Position player defense files (NOT pitchers)
|
|
POSITION_DEFENSE_FILES = [
|
|
"defense_c.csv",
|
|
"defense_1b.csv",
|
|
"defense_2b.csv",
|
|
"defense_3b.csv",
|
|
"defense_ss.csv",
|
|
"defense_lf.csv",
|
|
"defense_cf.csv",
|
|
"defense_rf.csv",
|
|
"defense_of.csv",
|
|
]
|
|
|
|
print("Undoing PO -> pickoffs rename for position player defense files...")
|
|
print("(Keeping pickoffs for defense_p.csv)")
|
|
print()
|
|
|
|
for filename in POSITION_DEFENSE_FILES:
|
|
filepath = os.path.join(DATA_DIR, filename)
|
|
|
|
if not os.path.exists(filepath):
|
|
print(f"⚠ Skipping {filename} (not found)")
|
|
continue
|
|
|
|
# Read CSV
|
|
df = pd.read_csv(filepath)
|
|
|
|
# Rename pickoffs back to PO if it exists
|
|
if "pickoffs" in df.columns:
|
|
df = df.rename(columns={"pickoffs": "PO"})
|
|
df.to_csv(filepath, index=False)
|
|
print(f"✓ {filename}: Renamed pickoffs -> PO")
|
|
else:
|
|
print(f"⚠ {filename}: Column 'pickoffs' not found")
|
|
|
|
print("\n✓ Position player defense files updated!")
|
|
print(" defense_p.csv still has 'pickoffs' column")
|