Skip to content

Excel skip blank lines #40095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ I/O
- :meth:`read_sql` returned an empty generator if ``chunksize`` was no-zero and the query returned no results. Now returns a generator with a single empty dataframe (:issue:`34411`)
- Bug in :func:`read_hdf` returning unexpected records when filtering on categorical string columns using ``where`` parameter (:issue:`39189`)
- Bug in :func:`read_sas` raising ``ValueError`` when ``datetimes`` were null (:issue:`39725`)
- Bug in :func:`read_excel` not accepting ``skip_blank_lines`` argument (:issue:`39808`)

Period
^^^^^^
Expand Down
9 changes: 9 additions & 0 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@
Detect missing value markers (empty strings and the value of na_values). In
data without any NAs, passing na_filter=False can improve the performance
of reading a large file.
skip_blank_lines : bool, default True
If True, skip over blank lines in single-column spreadsheets rather than
interpreting as NaN values.
verbose : bool, default False
Indicate number of NA values placed in non-numeric columns.
parse_dates : bool, list-like, or dict, default False
Expand Down Expand Up @@ -352,6 +355,7 @@ def read_excel(
na_values=None,
keep_default_na=True,
na_filter=True,
skip_blank_lines=True,
verbose=False,
parse_dates=False,
date_parser=None,
Expand Down Expand Up @@ -390,6 +394,7 @@ def read_excel(
na_values=na_values,
keep_default_na=keep_default_na,
na_filter=na_filter,
skip_blank_lines=skip_blank_lines,
verbose=verbose,
parse_dates=parse_dates,
date_parser=date_parser,
Expand Down Expand Up @@ -486,6 +491,7 @@ def parse(
skiprows=None,
nrows=None,
na_values=None,
skip_blank_lines=True,
verbose=False,
parse_dates=False,
date_parser=None,
Expand Down Expand Up @@ -598,6 +604,7 @@ def parse(
skiprows=skiprows,
nrows=nrows,
na_values=na_values,
skip_blank_lines=skip_blank_lines,
parse_dates=parse_dates,
date_parser=date_parser,
thousands=thousands,
Expand Down Expand Up @@ -1166,6 +1173,7 @@ def parse(
skiprows=None,
nrows=None,
na_values=None,
skip_blank_lines=True,
parse_dates=False,
date_parser=None,
thousands=None,
Expand Down Expand Up @@ -1199,6 +1207,7 @@ def parse(
skiprows=skiprows,
nrows=nrows,
na_values=na_values,
skip_blank_lines=skip_blank_lines,
parse_dates=parse_dates,
date_parser=date_parser,
thousands=thousands,
Expand Down
Binary file added pandas/tests/io/data/excel/one_col_blank_line.ods
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,20 @@ def test_no_header_with_list_index_col(self, read_ext):
)
tm.assert_frame_equal(expected, result)

def test_one_col_skip_blank_line(self, read_ext):
file_name = "one_col_blank_line" + read_ext
data = [0.5, 1, 2]
expected = DataFrame(data, columns=["numbers"])
result = pd.read_excel(file_name)
tm.assert_frame_equal(expected, result)

def test_one_col_noskip_blank_line(self, read_ext):
file_name = "one_col_blank_line" + read_ext
data = [0.5, np.nan, 1, 2]
expected = DataFrame(data, columns=["numbers"])
result = pd.read_excel(file_name, skip_blank_lines=False)
tm.assert_frame_equal(expected, result)


class TestExcelFileRead:
@pytest.fixture(autouse=True)
Expand Down