@@ -25,17 +25,20 @@ def load_table(config, config_dir):
25
25
26
26
Supports The following formats:
27
27
28
- CSV:
28
+ Excel or CSV:
29
29
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.
34
34
35
- Example ::
35
+ Examples ::
36
36
37
37
{"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}
39
42
40
43
Args:
41
44
config (dict): configuration specifying a source of data
@@ -52,12 +55,18 @@ def load_table(config, config_dir):
52
55
load_params = config ["params" ]
53
56
cwd = os .getcwd ()
54
57
try :
55
- os .chdir (config_dir )
58
+ if config_dir :
59
+ os .chdir (config_dir )
56
60
if load_type == "csv" :
57
61
path = os .path .abspath (os .path .relpath (load_params ["path" ]))
58
62
load_params = load_params .copy ()
59
63
del load_params ["path" ]
60
64
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 )
61
70
else :
62
71
raise NotImplementedError (
63
72
f"The specified table type { load_type } is not supported." )
0 commit comments