Generate repeatable fictional CSV data with Python
Creates ten fictional records with a fixed random seed, three-character IDs and no real personal data.
Before you start
- Python 3.10 or later. Run in a working folder with a backup of your source; output files may be replaced unless opened in exclusive mode.
python3 - <<'PY'
import csv
import random
rng = random.Random(42)
with open("output.csv", "w", encoding="utf-8", newline="") as target:
writer = csv.writer(target)
writer.writerow(["id", "label", "amount", "status", "note"])
for number in range(1, 11):
writer.writerow([f"{number:03}", f"Sample {number}", rng.randint(1, 100), "active", "Fictional"])
print("Wrote ten fictional records to output.csv")
PYLimits and output
- CSV has no stored type schema. Python keeps fields as strings until an example explicitly converts a value. These recipes do not add spreadsheet formula protection; import sensitive-looking strings as text in spreadsheets.
- This example has a fixed schema and distribution. Change the fields and ranges for your test rather than treating them as realistic production data.
Documentation: Python CSV reader and writer