put docstring on main function
This commit is contained in:
parent
701ec0d910
commit
dbd8dd8bbd
|
|
@ -8,6 +8,26 @@ EXT_MAP = {".ods": ods, ".fods": fods}
|
||||||
|
|
||||||
|
|
||||||
def read_ods(file_or_path, sheet=1, headers=True, columns=None):
|
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)
|
loader = EXT_MAP.get(Path(file_or_path).suffix)
|
||||||
if not loader:
|
if not loader:
|
||||||
raise ValueError("Unknown filetype.")
|
raise ValueError("Unknown filetype.")
|
||||||
|
|
|
||||||
|
|
@ -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):
|
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)
|
doc = ezodf.opendoc(file_or_path)
|
||||||
df = load_ods(doc, sheet, headers, columns)
|
df = load_ods(doc, sheet, headers, columns)
|
||||||
return sanitize_df(df)
|
return sanitize_df(df)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue