diff --git a/pandas_ods_reader/parser.py b/pandas_ods_reader/parser.py index fe18cfe..84c757f 100644 --- a/pandas_ods_reader/parser.py +++ b/pandas_ods_reader/parser.py @@ -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.") diff --git a/pandas_ods_reader/parsers/ods.py b/pandas_ods_reader/parsers/ods.py index 55d3a2b..783ff1e 100644 --- a/pandas_ods_reader/parsers/ods.py +++ b/pandas_ods_reader/parsers/ods.py @@ -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)