Skip to content

Commit 4fe0dba

Browse files
author
Scott Morken
committed
support for excel
1 parent 9152e02 commit 4fe0dba

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

libcbm/input/sit/sit_reader.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ def load_table(config, config_dir):
2525
2626
Supports The following formats:
2727
28-
CSV:
28+
Excel or CSV:
2929
30-
Used pandas.read_csv to load and return a pandas.DataFrame.
31-
With the exception of the "path" parameter, all parameters
32-
are passed as literal keyword args to the pandas.read_csv
33-
function.
30+
Uses pandas.read_csv or pandas.read_excel to load and return a
31+
pandas.DataFrame. With the exception of the "path" parameter, all
32+
parameters are passed as literal keyword args to the pandas.read_csv,
33+
or pandas.read_excel function.
3434
35-
Example::
35+
Examples::
3636
3737
{"type": "csv"
38-
"params": {"path": "my_file.csv", sep="\\t"}
38+
"params": {"path": "my_file.csv", "sep": "\\t"}
39+
40+
{"type": "excel"
41+
"params: {"path": "my_file.xls", "header": null}
3942
4043
Args:
4144
config (dict): configuration specifying a source of data
@@ -52,12 +55,18 @@ def load_table(config, config_dir):
5255
load_params = config["params"]
5356
cwd = os.getcwd()
5457
try:
55-
os.chdir(config_dir)
58+
if config_dir:
59+
os.chdir(config_dir)
5660
if load_type == "csv":
5761
path = os.path.abspath(os.path.relpath(load_params["path"]))
5862
load_params = load_params.copy()
5963
del load_params["path"]
6064
return pd.read_csv(path, **load_params)
65+
elif load_type == "excel":
66+
path = os.path.abspath(os.path.relpath(load_params["path"]))
67+
load_params = load_params.copy()
68+
del load_params["path"]
69+
return pd.read_excel(path, **load_params)
6170
else:
6271
raise NotImplementedError(
6372
f"The specified table type {load_type} is not supported.")

0 commit comments

Comments
 (0)