Skip to content
Merged
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
18 changes: 12 additions & 6 deletions gspread_pandas/spread.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def sheet_to_df(
unformatted_columns=None,
formula_columns=None,
sheet=None,
dropna=True,
):
"""
Pull a worksheet into a DataFrame.
Expand All @@ -382,6 +383,8 @@ def sheet_to_df(
optional, if you want to open a different sheet first,
see :meth:`open_sheet <gspread_pandas.spread.Spread.open_sheet>`
(default None)
dropna : bool
whether to remove rows where everything is null (default True)

Returns
-------
Expand All @@ -396,12 +399,15 @@ def sheet_to_df(
col_names = parse_sheet_headers(vals, header_rows)

# remove rows where everything is null, then replace nulls with ''
df = (
pd.DataFrame(vals[header_rows or 0 :])
.replace("", np.nan)
.dropna(how="all")
.fillna("")
)
if dropna:
df = (
pd.DataFrame(vals[header_rows or 0 :])
.replace("", np.nan)
.dropna(how="all")
.fillna("")
)
else: # do not remove rows where everything is null
df = pd.DataFrame(vals[header_rows or 0 :]).fillna("")

# replace values with a different value render option before we set the
# index in set_col_names
Expand Down