๐ File Operations ยท 7 min read
CSV Column Mixed Types: Why pandas Turns Numbers Into Text
A column that mixes numbers and words is read as text (object dtype) by pandas, because no single numeric type fits every value. The numbers come back as strings, so .sum() concatenates them into one long string instead of adding them, and on larger files the parser warns DtypeWarning: Columns (X) have mixed types. Specify dtype option on import or set low_memory=False.
The root cause is almost always one bad value in a sea of good ones: a stray twenty between 10 and 30, a blank cell, or a formula that wrote text where the rest of the column is numeric. One outlier demotes the entire column.
What Mixed Types Means
Consider a three-row column: 10, twenty, 30. The first and third values are numbers, the middle one is a word. pandas cannot store those as integers, because twenty is not an integer, so it falls back to the type that can hold anything: text.
This is the difference between a CSV and a spreadsheet. A spreadsheet keeps a type per cell, so row two can be text while the others are numbers. A CSV stores only characters, so the type has to be decided for the whole column when it is read, and one non-numeric value forces the least common denominator.
What pandas Does
We reproduced the behaviour on Python 3.13.5 with pandas 2.3.3. A three-row file with a mixed column read silently, with no warning, and the column came back as object dtype holding strings:
T2a. column with numbers then text (mixed types): amount dtype: object | values: ['10', 'twenty', '30']
The same condition on a larger file, 400,000 rows where the column turned from numbers to words partway down, produced the warning once:
warnings count: 1 DtypeWarning: Columns (1) have mixed types. Specify dtype option on import or set low_memory=False. amount dtype: object
So the outcome is identical either way, the column is text, but the warning only appears when the file is large enough to be scanned in chunks. On small files the demotion happens silently, which is how a mixed column slips into a report unnoticed.
The Silent Damage
The real problem is not the warning, it is what the demotion does downstream. Calling .sum() on the mixed column concatenates the values instead of adding them:
df['amount'].sum() -> 1234567891011121314151617... (string concat)
Sorting, .mean(), and every numeric operation behave the same way, they silently treat the numbers as text and produce a result that looks plausible but is wrong. This is the same family of failure as a column that sums as strings rather than numbers, which we walk through step by step in the guide to summing a column in CSV.
Why DtypeWarning Appears on Large Files Only
pandas infers the type of each column by scanning the file. On small files it can read everything at once and quietly settle on object. On large files it scans in chunks, and when one chunk disagrees with the type inferred from earlier chunks, it emits the DtypeWarning. The warning is a scan artefact, not a separate problem, the column was mixed either way.
How to Fix a Mixed Column
| Approach | What it does |
|---|---|
dtype=str on read | reads every column as text, so nothing is inferred wrong in the first place |
pd.to_numeric(..., errors="coerce") | converts numeric strings to numbers and turns the rest into NaN for inspection |
low_memory=False | only suppresses the warning, does not change the dtype |
| Fix the source data | remove the stray text value, or blank it, so the column is genuinely numeric |
The working combination, read everything as string, then coerce the one column, is deterministic and keeps the bad values visible. On our 3,000-row test file it produced a column with 501 non-numeric values turned into NaN and a correct sum of 3,123,750.0 over the numeric rows, instead of a silently concatenated string.
The common shortcut, adding low_memory=False to make the warning go away, does nothing to the data. We measured it directly: the warning count dropped to zero, but the column still came back as object dtype with the same string values. Silencing the warning and fixing the dtype are two different jobs.
What We Measured
Everything above was reproduced rather than assumed. The scripts live at /opt/data/cad_work/seo_geo_ops/nc_measure_20261112/ and ran on 2026-11-12 with Python 3.13.5 and pandas 2.3.3. The key numbers: a 3-row mixed column reads as object with no warning; a 400,000-row mixed column raises exactly one DtypeWarning; .sum() on the mixed column concatenates strings; and dtype=str plus pd.to_numeric(errors="coerce") recovers a correct numeric sum with the non-numeric rows flagged as NaN.
Frequently Asked Questions
Why does pandas read my numbers as text?
Because the column is not actually all numbers. When a column mixes numbers and words, pandas cannot pick a numeric type, so it falls back to object (text) and stores every value as a string. One stray word like 'twenty' is enough to demote the whole column.
What does DtypeWarning mean in pandas?
It means read_csv found a column whose values are not all the same type, so it cannot infer a single dtype. The warning says 'Columns (X) have mixed types. Specify dtype option on import or set low_memory=False.' On smaller files the same condition is often silent, which is why a mixed column can reach your analysis without any warning at all.
Why does .sum() return one long string instead of a number?
Because the column was read as object dtype, so its values are strings, and summing strings concatenates them. The numeric-looking values are joined end to end rather than added. Convert the column to numbers first with pd.to_numeric.
How do I fix a mixed-type column?
Read the column as string, then coerce it: df = pd.read_csv(path, dtype=str); df['amount'] = pd.to_numeric(df['amount'], errors='coerce'). Values that are not numbers become NaN, which you can inspect and clean. Setting low_memory=False only silences the warning; it does not change the dtype.
Is low_memory=False a fix for mixed types?
No. low_memory=False changes how pandas scans the file to infer dtypes and suppresses the DtypeWarning on large files, but the column still comes back as object dtype. The mixed values remain strings, and .sum() still concatenates. Only casting with pd.to_numeric actually converts the values.
Find the Mixed Column Before It Bites
Upload a CSV and the analyzer flags type drift and empty fields, so one stray word cannot silently turn a column into text.
Related reading
File Operations โ other guides that pair well with this one.
- check-csv-export-after-outage
- Split a Large CSV File Online
- CSV File Limit: How Many Rows Can a CSV File Have?
- CSV File Size Limit: How Big Can a CSV Get?
Browse all guides in the NoCodeCSV blog.