Skip to content

Commit 1cf4115

Browse files
authored
dropna parameter (#105)
1 parent 055f4c9 commit 1cf4115

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

gspread_pandas/spread.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def sheet_to_df(
360360
unformatted_columns=None,
361361
formula_columns=None,
362362
sheet=None,
363+
dropna=True,
363364
):
364365
"""
365366
Pull a worksheet into a DataFrame.
@@ -382,6 +383,8 @@ def sheet_to_df(
382383
optional, if you want to open a different sheet first,
383384
see :meth:`open_sheet <gspread_pandas.spread.Spread.open_sheet>`
384385
(default None)
386+
dropna : bool
387+
whether to remove rows where everything is null (default True)
385388
386389
Returns
387390
-------
@@ -396,12 +399,15 @@ def sheet_to_df(
396399
col_names = parse_sheet_headers(vals, header_rows)
397400

398401
# remove rows where everything is null, then replace nulls with ''
399-
df = (
400-
pd.DataFrame(vals[header_rows or 0 :])
401-
.replace("", np.nan)
402-
.dropna(how="all")
403-
.fillna("")
404-
)
402+
if dropna:
403+
df = (
404+
pd.DataFrame(vals[header_rows or 0 :])
405+
.replace("", np.nan)
406+
.dropna(how="all")
407+
.fillna("")
408+
)
409+
else: # do not remove rows where everything is null
410+
df = pd.DataFrame(vals[header_rows or 0 :]).fillna("")
405411

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

0 commit comments

Comments
 (0)