Why ML Still Runs on CSV
Parquet and Arrow win at scale, but CSV remains the universal exchange format for sharing datasets, Kaggle-style competitions, and quick experiments. If your CSV is messy, models learn the mess.
Dataset Shape Checklist
Before you fit anything, lock the table contract.
- One row = one example (or a documented grain).
- One header row with unique, stable names.
- Target column clearly named (label, target, y).
- No leakage columns (future info, IDs that encode the label).
- UTF-8, consistent delimiter, documented null tokens.
Step-by-Step: Load Cleanly in pandas
Be explicit—defaults hide landmines.
import pandas as pd
df = pd.read_csv(
"train.csv",
dtype={"user_id": "string"},
na_values=["", "NA", "null", "None"],
keep_default_na=True,
encoding="utf-8",
)
print(df.shape)
print(df.dtypes)
print(df.isna().mean().sort_values(ascending=False).head(10))Types, Categories, and IDs
Wrong dtypes quietly ruin features.
| Column kind | Store as | Notes |
|---|---|---|
| Entity IDs | string | Avoid float IDs; no leading-zero loss |
| Categoricals | string → category/codes later | Watch high cardinality |
| Numerics | float/int | Strip currency before parse |
| Timestamps | ISO 8601 → datetime | Keep timezone policy clear |
| Labels | explicit dtype | Map strings to ints deliberately |
Missing Values and Duplicates
Imputation belongs in the pipeline, but CSV hygiene still matters.
- Decide whether blank, NA, and N/A mean the same thing.
- Drop exact duplicate rows only when the grain says they are errors.
- Do not impute before splitting train/validation/test.
- Record missingness rates in a data card.
Train / Validation / Test Files
Prefer separate files or an explicit split column over ad-hoc slicing in notebooks you will forget.
train.csv # fitting
valid.csv # early stopping / model selection
test.csv # final estimate (labels optional for competitions)From Spreadsheets and APIs to ML CSV
Excel sources need Excel to CSV with UTF-8. Nested JSON labels need JSON to CSV with a fixed schema. Preview in the Online CSV Editor before you commit a dataset version.
Real-World Examples
Patterns from real training workflows.
Tabular churn model
CSV exports from the warehouse, string IDs, boolean flags as 0/1, time-based split instead of random split.
NLP fine-tuning input
Two-column CSV: text,label—no extra commas unquoted, UTF-8 for non-English text.
Feature store extract
Point-in-time correct features dumped to CSV for a baseline model before moving to Parquet.
Common Mistakes
These leak accuracy you do not deserve—or kill generalization.
- Random splits on time-series problems.
- Leaving target-derived columns in features.
- Parsing IDs as numbers.
- Fitting preprocessors on train+test together.
- Undocumented delimiter changes between train and test files.
Best Practices
Reproducibility first.
- Version raw and cleaned CSV with checksums.
- Keep a short data dictionary.
- Fit transforms on train only.
- Assert schemas in CI (column sets and dtypes).
- Graduate to Parquet when size or types demand it—after the logic is right.
Why Use Convert CSV Online?
Convert CSV Online is free, browser-based, and requires no account for everyday conversions. Inspect schema, convert Excel/JSON sources into flat training tables, and catch delimiter issues before they poison an experiment. Client-side workflows work on Windows, macOS, and Linux browsers.
Quicker dataset QA
A five-minute preview often saves a five-hour "why is AUC 0.99" investigation.
Conclusion
ML-ready CSV is explicit about grain, types, nulls, and splits. Clean the contract first—models cannot fix a broken table definition.
FAQ
Is CSV good enough for machine learning?
Yes for many tabular experiments and data exchange. Use Parquet/Arrow when you need better types, compression, or speed at scale.
How should I handle missing values in ML CSV files?
Document null tokens, load them consistently, and impute only inside a pipeline fitted on training data—not before the split.
Should ID columns be features?
Usually no. Keep IDs as strings for joins and auditing; exclude them from model features unless they are true signals.
How do I split CSV for train and test?
Use separate files or a split column. Prefer time-based splits for temporal problems instead of random sampling.
What encoding should ML datasets use?
UTF-8. Non-UTF-8 text leads to parse errors and silent corruption in tokenizers and string features.
How do I convert Excel to an ML CSV?
Export via Excel to CSV (UTF-8), verify headers and types in the Online CSV Editor, then version the file for training.
References
Convert your CSV in the browser
Preview, clean, and convert CSV files free with Convert CSV Online—no installation and no account required for everyday conversions.