pandas "ValueError: could not convert string to float" in CI
pandas raises "ValueError: could not convert string to float" when a column you treat as numeric holds a value it cannot parse, like an empty string, a thousands separator, or a stray label, during astype or a numeric operation.
What this error means
A data step fails with "ValueError: could not convert string to float: 'N/A'" (or similar) during astype(float), pd.to_numeric, or a numeric aggregation in CI.
ValueError: could not convert string to float: 'N/A'Common causes
Non-numeric sentinels in a numeric column
Values like "N/A", "-", or "" sit in a column you cast to float, and pandas cannot parse them.
Locale or formatting in the raw data
Thousands separators or currency symbols make the string unparseable as a plain float.
How to fix it
Coerce with to_numeric and handle bad values
- Use
pd.to_numeric(..., errors="coerce")so unparseable values become NaN instead of raising. - Decide how to handle the resulting NaNs (drop, fill, or fail explicitly).
- Re-run the numeric step.
df["amount"] = pd.to_numeric(df["amount"], errors="coerce")Clean formatting before conversion
Strip separators and symbols, then convert, when the raw values are numeric but formatted.
df["amount"] = (df["amount"].str.replace(",", "", regex=False)).astype(float)How to prevent it
- Validate column dtypes against a schema in CI.
- Use
errors="coerce"and assert the NaN rate is acceptable. - Normalize sentinels and formatting at ingestion.