The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Python raises ValueError when float() receives a string whose contents do not match its numeric format. Inspect the exact value first, then choose a fix that matches the input: remove known decoration, parse the correct locale, handle invalid rows deliberately, or use a decimal type when needed.
Why float() raises this error
The argument can be a string and still contain an invalid value. Python’s float() accepts numeric text such as signed decimals and exponent notation, along with surrounding whitespace and spellings for infinity and NaN. It does not accept arbitrary words, currency symbols, or punctuation that conflicts with the numeric syntax. See the Python 3.14.7 float() reference and the Python 3.12.15 definition of ValueError.
As an Amazon Associate I earn from qualifying purchases.
For example, float(" 12.5 ") works because surrounding whitespace is allowed. But float("$12.50") and float("12,50") fail: the first includes a currency mark, and the second may use a decimal convention that Python does not infer.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallFive fixes for the error
1. Inspect the exact string
Print the value with repr() immediately before conversion. It reveals characters that ordinary printing can hide, such as tabs and newlines.
#1 Best Overall
print(repr(value))
number = float(value)
If conversion fails, identify which input record produced the value and check the upstream source. Catching the exception without recording or examining the bad value can conceal a data-quality problem rather than fix it.
2. Remove only known decoration
Python already accepts whitespace at the beginning and end of a numeric string, so trimming alone will not remove a currency symbol, label, or other unexpected character. If the input format guarantees a particular decoration, remove that specific text before parsing.
Rank #2
value = "$12.50"
cleaned = value.removeprefix("$")
number = float(cleaned)
Do not strip punctuation indiscriminately. Deleting every comma, for example, can turn a decimal value into a different number. Normalize only characters whose meaning is established by the source format.
3. Parse separators using the source’s locale
Grouping and decimal separators vary. For instance, 1,234.50 and 1.234,50 represent the same quantity under different conventions. Decide which convention the source uses before parsing; punctuation removal without that knowledge can silently corrupt values.
For locale-defined input, configure the intended numeric locale and use locale.atof(), which interprets separators according to that locale. The setting must match the data source. Python documents this behavior in its locale conversion reference.
import locale
# Configure the intended LC_NUMERIC in the application first.
number = locale.atof("1.234,50")
4. Parse a pandas column deliberately
For a Series or other one-dimensional collection, pandas.to_numeric() raises on invalid values by default. If the workflow should retain valid entries while marking invalid ones, use errors="coerce"; those invalid entries become NaN, so inspect and report them rather than treating them as valid data.
import pandas as pd
values = pd.Series(["1.5", "not available", "2.0"])
parsed = pd.to_numeric(values, errors="coerce")
bad_rows = values[parsed.isna()]
print(bad_rows)
Choose coercion only when a missing-value marker is appropriate for the application. The pandas 3.0.6 API reference also cautions that very large values may lose precision in array-backed numeric storage.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →5. Use Decimal when decimal arithmetic matters
If the domain requires decimal representation, such as calculations where decimal rounding matters, parse a valid decimal string with Decimal instead of converting it to a binary floating-point number.
Best Value
from decimal import Decimal
amount = Decimal("12.50")
Decimal has its own accepted string syntax; it is not a general parser for currency-formatted text. Remove or interpret formatting according to the input’s known rules before constructing the value. See the Python 3.14.8 Decimal documentation.
Which fix should you choose?
| Situation | Approach | Important check |
|---|---|---|
| You do not know what the failing value contains | Inspect it with repr() |
Trace the value to its source record |
| The input has a known symbol or label | Remove that exact decoration, then call float() |
Do not remove punctuation with unknown meaning |
| Numbers use locale-specific separators | Use the matching locale with locale.atof(), or a validated format-specific normalization |
Confirm the source convention and locale |
| You are parsing a pandas column and want invalid entries marked missing | Use pd.to_numeric(..., errors="coerce") |
Find and review the resulting NaN rows |
| Decimal representation is required | Use Decimal with valid decimal text |
It does not automatically parse formatted currency |
Do not use eval() as a conversion shortcut
eval() is not a safe way to turn text into a number: Python’s FAQ notes that it is slower and creates a security risk. Use a numeric parser suited to the actual input format instead. See the Python 3.14.7 numeric-conversion FAQ.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Recommended Free Tools




