put docstring on main function

This commit is contained in:
iuvbio 2021-08-20 20:28:26 +02:00
parent 701ec0d910
commit dbd8dd8bbd
2 changed files with 20 additions and 17 deletions

View File

@ -8,6 +8,26 @@ EXT_MAP = {".ods": ods, ".fods": fods}
def read_ods(file_or_path, sheet=1, headers=True, columns=None):
"""
Read in the provided ods file and convert it to `pandas.DataFrame`.
Parameters
----------
file_or_path : str
The path to the .ods or .fods file.
sheet : int or str, default 1
If `int`, the 1 based index of the sheet to be read. If `str`, the
name of the sheet to be read.
header : bool, default True
If `True`, then the first row is treated as the list of column names.
columns : list or None, optional
A list of column names to be used as headers.
Returns
-------
pandas.DataFrame
The content of the specified sheet as a DataFrame.
"""
loader = EXT_MAP.get(Path(file_or_path).suffix)
if not loader:
raise ValueError("Unknown filetype.")

View File

@ -57,23 +57,6 @@ def load_ods(doc, sheet_id, headers=True, columns=None):
def read(file_or_path, sheet=1, headers=True, columns=None):
"""
This function reads in the provided ods file and converts it to a
dictionary. The dictionary is converted to a DataFrame. Trailing empty rows
and columns are dropped from the DataFrame, before it is returned.
:param file_or_path: str
the path to the ODS file
:param sheet: int or str, default 1
if int, the 1 based index of the sheet to be read in. If str, the name of
the sheet to be read in
:param header: bool, default True
if True, the first row is read in as headers
:param columns: list, default None
a list of column names to be used as headers
:returns: pandas.DataFrame
the ODS file as a pandas DataFrame
"""
doc = ezodf.opendoc(file_or_path)
df = load_ods(doc, sheet, headers, columns)
return sanitize_df(df)