Files
website/scripts/stats/vparty-csv.py
2026-10-25 22:16:25 +00:00

15 lines
613 B
Python

# Convert V-Dem's vparty.RData to CSV on stdout (selected columns only). Run with the stats
# Python venv (pyreadr + pandas): ~/.local/share/stats-py/bin/python vparty-csv.py file.RData
import sys
import pyreadr
COLS = [
"v2paid", "pf_party_id", "CHES_ID", "country_text_id", "year", "v2paenname", "v2pashname",
"v2pavote", "v2paseatshare", "v2xpa_popul", "v2xpa_antiplural", "v2pariglef", "v2paimmig",
"v2palgbt", "v2parelig", "v2pawelf", "v2paculsup",
]
frames = pyreadr.read_r(sys.argv[1])
df = next(iter(frames.values()))
df[[c for c in COLS if c in df.columns]].to_csv(sys.stdout, index=False)