Repository navigation
fix: keep blank cells blank and NA-like text intact in XLSX/XLS - #2824
Open
Dheeraj Piduru (DheerajPiduru52) wants to merge 1 commit into
Open
Dheeraj Piduru (DheerajPiduru52) wants to merge 1 commit into
Dheeraj Piduru (DheerajPiduru52) wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 | 1andUnknown | 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.