Skip to content

fix: keep blank cells blank and NA-like text intact in XLSX/XLS - #2824

Open
Dheeraj Piduru (DheerajPiduru52) wants to merge 1 commit into
microsoft:mainfrom
DheerajPiduru52:fix/xlsx-blank-cells-not-nan
Open

Dheeraj Piduru (DheerajPiduru52) wants to merge 1 commit into
microsoft:mainfrom
DheerajPiduru52:fix/xlsx-blank-cells-not-nan

Conversation

@DheerajPiduru52

Copy link
Copy Markdown

pandas.read_excel treats empty cells and strings such as 'NA', 'N/A', 'null' and 'nan' as missing values by default. As a result, blank cells rendered as 'NaN', integer columns containing a blank became floats (1 -> 1.0), and real text like the country code 'NA' (Namibia) was silently replaced with 'NaN'.

Pass keep_default_na=False to every read_excel call so cells are kept exactly as written in the workbook.

Repro: an XLSX with rows Namibia | NA | 1 and Unknown | N/A | (blank) converts to | Namibia | NaN | 1.0 | and | Unknown | NaN | NaN |. With the fix: | Namibia | NA | 1 | and | Unknown | N/A | |. Adds a regression test that fails without the fix.

pandas.read_excel treats empty cells and strings such as 'NA', 'N/A',
'null' and 'nan' as missing values by default. As a result, blank cells
rendered as 'NaN', integer columns containing a blank became floats
(1 -> 1.0), and real text like the country code 'NA' (Namibia) was
silently replaced with 'NaN'.

Pass keep_default_na=False to every read_excel call so cells are kept
exactly as written in the workbook.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant