Skip to content
Latchkey

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.

pandas
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

  1. Use pd.to_numeric(..., errors="coerce") so unparseable values become NaN instead of raising.
  2. Decide how to handle the resulting NaNs (drop, fill, or fail explicitly).
  3. Re-run the numeric step.
pandas
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.

pandas
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.

Frequently asked questions

What causes "pandas "could not convert string to float""?
Values like "N/A", "-", or "" sit in a column you cast to float, and pandas cannot parse them.
How do I fix pandas "could not convert string to float"?
Coerce with to_numeric and handle bad values

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card