table_func module¶
This module contains table (file) functions.
It comprises reading, writing and a limited number of manipulations.
The data is stored in numpy recarrays.
The main purpose of the module is to make it easier to read and write different formats of table files.
-
table_func.
add_to_recarr
(arr, dt_or_arr, nodata=0)¶ Function to add fields to a numpy recarray.
Parameters: arr : numpy recarray
dt_or_arr : list of dtype(s) or numpy recarray
The dtypes of the fields to be added or the recarray to be added.
If dt_or_arr is specified as list it should be a list of dtypes in the form (field name, dtype).
If dt_or_arr is a recarray containing field names which already exist in arr these field names are extended with a number. If the number of records differs from arr records are removed or new records are added to dt_or_arr.
nodata : bool, int, float, str or sequence (optional)
Nodata value(s) to be applied if dt_or_arr is specified as dtype.
If nodata is a single value (bool, int or float) this value is applied for all fields, if possible.
If nodata is a sequence (list, tuple or array) it should contain one value for each field.
Returns: result : numpy recarray
-
table_func.
arr2csv
(arr, f_csv, header=True, formats=[‘%s’])¶ Function to write numpy recarray to a comma-separated file.
Parameters: arr : numpy recarray
f_table : str
Comma-separated file.
header : bool
True = a header line containing the field names is written.
False = no header line is written.
formats : str, sequence or None (optional)
The Python % format(s) used to write the values.
See http://docs.python.org/2/library/stdtypes.html#string-formatting-operations.
If formats is None the format ‘%s’ is used.
-
table_func.
arr2dat
(arr, f_dat, header=True, formats=[‘%s’])¶ Function to write numpy recarray to a space-separated file.
Parameters: arr : numpy recarray
f_dat : str
Space-separated file.
header : bool
True = a header line containing the field names is written.
False = no header line is written.
formats : str, sequence or None (optional)
The Python % format(s) used to write the values.
See http://docs.python.org/2/library/stdtypes.html#string-formatting-operations.
If formats is None the format ‘%s’ is used.
-
table_func.
arr2dbf
(arr, f_dbf, fieldspecs=None)¶ Function to write numpy recarray to a DBF file.
Parameters: arr : numpy recarray
f_dbf : str
DBF file.
fieldspecs : list or None (optional)
List of field specs in the form (type, size, deci).
See DBF files and
arr2dbfspecs <table_func.arr2dbfspecs()
.If fieldspecs is None the specs are determined automatically.
See also
-
table_func.
arr2dbfspecs
(arr)¶ Function to get DBF field specs for a numpy recarray.
Parameters: arr : numpy recarray
Returns: dbfspecs : list
List with field specs in the form (type, size, deci).
See DBF files.
See also
-
table_func.
arr2imodtss
(arr, f_tss, l_nodata=-999999, delimiter=’, ’)¶ Function to write a numpy recarray to an iMOD timeseries file.
Parameters: arr : numpy recarray
f_tss : str
iMOD timeseries file.
l_nodata : dict, list, int or float (optional)
Nodata values(s) of the fields.
If l_nodata is a dict the keys in the dict are the field names and the values the nodata values.
If l_nodata is a single value (int, float) this value is used for all fields.
delimiter : str (optional)
The delimiter/separator used to separate values.
-
table_func.
arr2ipf
(arr, f_ipf, formats=[‘%s’], delimiter=’,’, i_ext=0, relpath=False)¶ Function to write a numpy recarray to an iMOD IPF file.
Parameters: arr : numpy recarray
f_ipf : str
iMOD IPF file.
formats : str, sequence or None (optional)
The Python % format(s) used to write the values.
See http://docs.python.org/2/library/stdtypes.html#string-formatting-operations.
If formats is None the format ‘%s’ is used.
delimiter : str (optional)
The delimiter/separator used to separate values.
i_ext : int (optional)
Index number.
See iMOD IPF file.
The extension is determined automatically and (if possbile) stripped off from the values in the field. If this is not possible the extension is set to ‘TXT’ by default.
relpath : bool (optional)
True = convert references to iMOD timeseries files (if existing) to relative path names.
False = do not convert references to iMOD timeseries files (if existing) to relative path names.
-
table_func.
arr2table
(arr, f_table, formats=[‘%s’], delimiter=’ ‘, i_ext=0, relpath=False, fieldspecs=None)¶ Function to write a numpy recarray to a table file.
The table file could be a comma-separated file (*.csv), DBF file (*.dbf), iMOD IPF file (*.ipf) or space-separated file. The first three file types are recognized by the file extension.
There are also separate writers for the various file formats, but this overall writer is suitable for most cases.
Parameters: arr : numpy recarray
f_table : str
Table file name.
formats : str, sequence or None (optional)
The Python % format(s) used to write the values.
Only relevant for text-formatted files (including iMOD IPF files).
See http://docs.python.org/2/library/stdtypes.html#string-formatting-operations.
If formats is None the format ‘%s’ is used.
delimiter : str (optional)
The delimiter/separator used to separate values.
Only relevant for iMOD files and text-formatted files other than *.csv.
i_ext : int (optional)
Index number. Only relevant for iMOD IPF files.
See iMOD IPF file.
relpath : bool (optional)
Only relevant for iMOD IPF files.
True = convert references to iMOD timeseries files (if existing) to relative path names.
False = do not convert references to iMOD timeseries files (if existing) to relative path names.
fieldspecs : list or None (optional)
List of field specs in the form (type, size, deci). Only relevant for DBF files.
See DBF files and
arr2dbfspecs <table_func.arr2dbfspecs()
.If fieldspecs is None the specs are determined automatically.
See also
-
table_func.
arr2txt
(arr, f_txt, delimiter=’,’, header=True, formats=[‘%s’])¶ Function to write a numpy recarray to a text-formatted table file.
Parameters: arr : numpy recarray
f_txt : str
Text-formatted file.
delimiter : str (optional)
The delimiter/separator used to separate values.
header : bool
True = a header line containing the field names is written.
False = no header line is written.
formats : str, sequence or None (optional)
The Python % format(s) used to write the values.
See http://docs.python.org/2/library/stdtypes.html#string-formatting-operations.
If formats is None the format ‘%s’ is used.
-
table_func.
change_dtype
(arr, flds, new_types)¶ Function to change the datatype (dtype) of specific fields in a numpy recarray.
Parameters: arr : numpy recarray
flds: list
List of fields to be changed.
new_types : list
List of new dtypes.
Returns: result : numpy recarray
-
table_func.
csv2arr
(f_csv, n_header=1, l_flds=None, fld_str=None)¶ Function to read a comma-separated file and create a numpy recarray.
It is not necessary to read the entire table file, but a selection of fields could be made. This is useful for large table files if not all fields are to be usued.
Parameters: f_csv : str
Comma-separated file.
n_header : int (optional)
Number of header lines. The field names are expected to be in the last line of the header.
l_flds : list or None (optional)
List of field names to read. If l_flds is None all fields are read.
fld_str : str or None (optional)
An arbitrary string which is scanned for occurences of field names. Occuring field names will be included in the list of fields to be read.
Such a string could originate from user input, e.g. a condition string which is specified in an input file for a tool.
Returns: result : numpy recarray
-
table_func.
csv2fields
(f_csv, n_header=1)¶ Function to get the field names of a comma-separated file.
Parameters: f_csv : str
Comma-separated file.
n_header : int (optional)
Number of header lines. The field names are expected to be in the last line of the header.
Returns: result : list
List of the field names.
See also
-
table_func.
dat2arr
(f_dat, n_header=1, l_flds=None, fld_str=None)¶ Function to read a space-separated file and create a numpy recarray.
It is not necessary to read the entire table file, but a selection of fields could be made. This is useful for large table files if not all fields are to be usued.
Parameters: f_dat : str
Space-separated file.
n_header : int (optional)
Number of header lines. The field names are expected to be in the last line of the header.
l_flds : list or None (optional)
List of field names to read. If l_flds is None all fields are read.
fld_str : str or None (optional)
An arbitrary string which is scanned for occurences of field names. Occuring field names will be included in the list of fields to be read.
Such a string could originate from user input, e.g. a condition string which is specified in an input file for a tool.
Returns: result : numpy recarray
-
table_func.
dat2fields
(f_dat, n_header=1)¶ Function to get the field names of a space-separated file.
Parameters: f_dat : str
Space-separated file.
n_header : int (optional)
Number of header lines. The field names are expected to be in the last line of the header.
Returns: result : list
List of the field names.
See also
-
table_func.
dbf2arr
(f_dbf, l_flds=None, fld_str=None)¶ Function to read a DBF file and create a numpy recarray.
It is not necessary to read the entire table file, but a selection of fields could be made. This is useful for large table files if not all fields are to be usued.
Parameters: f_dbf : str
DBF file.
l_flds : list or None (optional)
List of field names to read. If l_flds is None all fields are read.
fld_str : str or None (optional)
An arbitrary string which is scanned for occurences of field names. Occuring field names will be included in the list of fields to be read.
Such a string could originate from user input, e.g. a condition string which is specified in an input file for a tool.
Returns: result : numpy recarray
See also
-
table_func.
dbf2fields
(f_dbf)¶ Function to get the field names of a DBF file.
Parameters: f_dbf : str
DBF file.
Returns: result : list
List of the field names.
See also
-
table_func.
dbf2fields_specs
(f_dbf)¶ Function to get the field names and field specs of a DBF file.
Returns: result : list
The returned list contains:
List with field names.
List with field specs in the form (type, size, deci).
See also
-
table_func.
dbfreader
(f, only_fields=False, l_flds=None)¶ Function to create a generator over records in a DBF file.
Adapted from: http://code.activestate.com/recipes/362715-dbf-reader-and-writer/
Parameters: f : file object (DBF file opened for binary reading)
only_fields : bool (optional)
True = only field names and specs are returned.
False = field names and specs and data records are returned.
l_flds : list or None (optional)
List of field names to read. If l_flds is None all fields are read.
Returns: result : generator
First row: field names.
Second row: field specs (type, size, decimal places).
Subsequent rows: data records.
-
table_func.
dbfwriter
(f, fieldnames, fieldspecs, records)¶ Function to create and write a binary string directly to an opened DBF file.
Adapted from: http://code.activestate.com/recipes/362715-dbf-reader-and-writer/
Parameters: f : file object (file opened for binary writing)
fieldnames : list
List of fieldnames.
Fieldnames should be no longer than ten characters and not include x00.
fieldspecs : list
List of fieldspecs for each field.
Fieldspecs are in the form (type, size, deci) where
type is one of:
C for ascii character data
M for ascii character memo data (real memo fields not supported)
D for datetime objects
N for ints or decimal objects
F for floats
L for logical values ‘T’, ‘F’, or ‘?’
size is the field width
deci is the number of decimal places in the provided decimal object
records : array or array_like
Sequences of field values (the records or rows of the table).
-
table_func.
dtype2nodata
(dtype)¶
-
table_func.
get_fields
(f_table, delimiter=’, ’, autostrip=False, n_header=1)¶ Function to get the field names of a text-formatted table file.
Parameters: f_table : str
Text-formatted table file.
It is assumed that the field names are on one header line (in contrast to the text-formatted iMOD IPF file).
delimiter : str or None
The delimiter/separator used to separate values.
If delimiter is None it is assumed that the file is space-separated.
Returns: result : list
List of the field names.
-
table_func.
imodtss2arr
(f_tss, l_flds=None, fld_str=None)¶ Function to read an iMOD timeseries file and create a numpy recarray.
It is not necessary to read the entire table file, but a selection of fields could be made. This is useful for large table files if not all fields are to be usued.
Parameters: f_tss : str
iMOD timeseries file.
l_flds : list or None (optional)
List of field names to read. If l_flds is None all fields are read.
fld_str : str or None (optional)
An arbitrary string which is scanned for occurences of field names. Occuring field names will be included in the list of fields to be read.
Such a string could originate from user input, e.g. a condition string which is specified in an input file for a tool.
Returns: data : numpy recarray
nodata : dict
The returned dict contains the nodata values of the fields in the numpy recarray.
See also
-
table_func.
ipf2arr
(f_ipf, l_flds=None, fld_str=None, abspath=False)¶ Function to read an iMOD IPF file and create a numpy recarray.
It is not necessary to read the entire table file, but a selection of fields could be made. This is useful for large table files if not all fields are to be usued.
Parameters: f_ipf : str
iMOD IPF file.
l_flds : list or None (optional)
List of field names to read. If l_flds is None all fields are read.
fld_str : str or None (optional)
An arbitrary string which is scanned for occurences of field names. Occuring field names will be included in the list of fields to be read.
Such a string could originate from user input, e.g. a condition string which is specified in an input file for a tool.
abspath : bool (optional)
True = convert references to iMOD timeseries files (if existing) to absolute path names.
False = do not convert references to iMOD timeseries files (if existing) to absolute path names.
Returns: result : numpy recarray
-
table_func.
ipf2fields
(f_ipf)¶ Function to get the field names of an iMOD IPF file.
Parameters: f_ipf : str
iMOD IPF file.
Returns: result : list
List of the field names.
See also
-
table_func.
ipf2iext
(f_ipf)¶ Function to get the field number of the iMOD timeseries file references (IEXT) and the extension (EXT) from an iMOD IPF file.
Parameters: f_ipf : str
iMOD IPF file.
Returns: iext : int
Field number of timeseries file references. The values in this field refer to iMOD timeseries files.
0 = no timeseries file references specified.
1 = first field
etc.
ext : str
Extension of timeseries files.
See also
-
table_func.
make_recarr
(n, dt, nodata=0)¶ Function to create a numpy recarray filled with nodata.
Parameters: n : int
Number of records.
dt : list
List of dtypes in the form (field name, dtype).
nodata : bool, int, float, str or sequence (optional)
Nodata value(s).
If nodata is a single value (bool, int or float) this value is applied for all fields, if possible.
If nodata is a sequence (list, tuple or array) it should contain one value for each field.
Returns: result : numpy recarray
-
table_func.
recarray2ndarray
(arr, i_flds=None, format=None)¶ Function to convert a numpy recarray to a regular numpy ndarray.
Parameters: arr : numpy recarray
i_flds : list, int or None (optional)
The index number(s) of the field(s) to be converted.
If i_flds is None all fields are read.
format : dtype or None (optional)
The dtype to convert the data to.
If format is None the dtype is taken from the first field to be converted.
Returns: result : numpy ndarray
-
table_func.
remove_from_recarr
(arr, flds)¶ Function to remove fields from a numpy recarray.
Parameters: arr : numpy recarray
flds: list
List of fields to be removed.
Returns: result : numpy recarray
-
table_func.
replace_string
(s, sourceList=[], targetList=[], whitespaceTarget=None, keeptogether=[[‘”’]])¶ Function to replace substrings by other substrings.
Parameters: s : string
Source string within which substrings are replaced.
sourceList : list (optional)
List containing substrings to be replaced.
targetList : list (optional)
List containing substrings which are used as replacements. If the number of strings is less than in sourceList then empty strings are used.
whitespaceTarget : string or None (optional)
String to be used as replacement for whitespace. None = not specified.
keeptogether : list or None (optional)
List containing the string(s) between which replacements are not performed (e.g. double quotes). Examples:
[] or None = not specified
[‘”’] = between double quotes no replacements are performed
[[‘(‘, ‘)’] , ‘”’] = between parentheses (open and close parenthesis) and double quotes no replacements are performed
Returns: result : string
Resulting string.
-
table_func.
split_csv
(s, commaSplit=True, semicolonSplit=False, whitespaceSplit=False, multiLines=False)¶ Function to split a string according to ‘csv’ rules.
Split on commas and/or semicolons and/or whitespace. String may contain multiple lines, in which case \n is used as delimiter.
Double-quoted substrings are not split.
Whitespace is stripped off from the substrings.
Parameters: s : string
The string to be split.
commaSplit : bool (optional)
True = comma is used as delimiter.
False = comma is not used as delimiter.
semicolonSplit : bool (optional)
True = semicolon is used as delimiter.
False = semicolon is not used as delimiter.
whitespaceSplit : bool (optional)
True = whitespace is used as delimiter. Whitespace around comma or semicolon is not treated as separate delimiter.
False = whitespace is not used as delimiter.
multiLines : bool (optional)
True = string is split into multiple lines at occurences of \n.
False = string is not split into multiple lines.
Returns: record : list
Record contains the substrings. If multiLines is True then a list of records is returned.
-
table_func.
split_freeformat
(s)¶ Function to split a string according to ‘freeformat’ rules.
Split on whitespace and commas. Subsequent delimiters (whitespace and commas) are treated as one delimiter.
Double-quoted substrings are not split.
Whitespace is stripped off from the substrings.
Parameters: s : string
The string to be split.
Returns: record : list
Record contains the substrings.
-
table_func.
split_ipf
(s, multiLines=False)¶ Function to split a string according to ‘ipf’ rules.
Split on whitespace, commas and semicolons. String may contain multiple lines, in which case \n is used as delimiter.
Double-quoted substrings are not split.
Whitespace is stripped off from the substrings.
Parameters: s : string
The string to be split.
multiLines : bool (optional)
True = string is split into multiple lines at occurences of \n.
False = string is not split into multiple lines.
Returns: record : list
Record contains the substrings. If multiLines is True then a list of records is returned.
-
table_func.
split_string
(s, splitList=[‘,’], whitespace=True, autostrip=True, keeptogether=[[‘”’]], removekeepChars=[‘”’], double2one=False, multiLines=False)¶ Function to split a string using one or more delimiters.
Parameters: s :
String to be split.
splitList : list (optional)
List containing the delimiter string(s). This may be an empty list if no delimiter string will apply.
whitespace : bool (optional)
True = whitespace is used as delimiter. Whitespace around other delimiters is not treated as separate delimiter.
False = whitespace is not used as delimiter.
autostrip : bool (optional)
True = whitespace is stripped off from the substrings.
False = whitespace is not stripped off.
keeptogether : list or None (optional)
List containing the string(s) between which the string is not split (e.g. double quotes). Examples:
[] or None = not specified
[‘”’] = substrings between double quotes are not split
[[‘(‘, ‘)’] , ‘”’] = substrings between parentheses (open and close parenthesis) and substrings between double quotes are not split
removekeepChars : list or None (optional)
List of strings specified at keeptogether which should be removed from the resulting substrings.
[] or None = not specified, all (optional) strings specified at keeptogether will be preserved.
[‘”’] = double quotes will be removed from the respective substrings.
[‘(‘, ‘)’, ‘”’] = parentheses and double quotes will be removed from the respective substrings.
double2one : bool (optional)
True = subsequent (double or multiple) delimiters are treated as one delimiter.
False = subsequent delimiters are treated as separate delimiters.
multiLines : bool (optional)
True = string is split into multiple lines at occurences of \n.
False = string is not split into multiple lines.
Returns: record : list
Record contains the substrings.
-
table_func.
table2arr
(f_table, l_flds=None, n_header=1, fld_str=None, abspath=False, sheet=0)¶ Function to read a table file and create a numpy recarray (structured array).
The table file could be a comma-separated file (*.csv), DBF file (*.dbf), Excel file (*.xls, *.xlsx), iMOD IPF file (*.ipf) or space-separated file. The first three file types are recognized by the file extension.
It is not necessary to read the entire table file, but a selection of fields could be made. This is useful for large table files if not all fields are to be usued.
There are also separate readers for the various file formats, but this overall reader is suitable for most cases.
Parameters: f_table : str
Table file name.
l_flds : list or None (optional)
List of field names to read. If l_flds is None all fields are read.
n_header : int (optional)
Number of header lines. Only relevant for comma- and space-separated files and Excel files. The field names are expected to be in the last line of the header.
fld_str : str or None (optional)
An arbitrary string which is scanned for occurences of field names. Occuring field names will be included in the list of fields to be read.
Such a string could originate from user input, e.g. a condition string which is specified in an input file for a tool.
abspath : bool (optional)
Only relevant for iMOD IPF files.
True = convert references to iMOD timeseries files (if existing) to absolute path names.
False = do not convert references to iMOD timeseries files (if existing) to absolute path names.
sheet : int or str (optional)
Sheet index number or sheet name. Only relevant for Excel files.
Returns: result : numpy recarray
See also
-
table_func.
table2fields
(f_table, n_header=1, sheet=0)¶ Function to get the field names of a table file.
Parameters: f_table : str
Table file name.
n_header : int (optional)
Number of header lines. Only relevant for comma- and space-separated files and Excel files. The field names are expected to be in the last line of the header.
sheet : int or str (optional)
Sheet index number or sheet name. Onley relevant for Excel files.
Returns: result : list
List of the field names.
See also
-
table_func.
take_from_recarr
(arr, flds)¶ Function to take specific fields from a numpy recarray.
Parameters: arr : numpy recarray
flds : sequence
Field name(s) to be taken from arr.
If a field name occurs more than once in flds the field name is extended with a number.
Returns: result : numpy recarray
-
table_func.
txt2arr
(f_table, delimiter=’, ’, autostrip=False, i_flds=None, formats=None, n_header=0, recarr2ndarr=False)¶ Function to read a text-formatted table file and create a numpy recarray or ndarray.
Parameters: f_table : str
Text-formatted table file.
delimiter : str or None (optional)
The delimiter/separator used to separate values.
If delimiter is None it is assumed that the file is space-separated.
autostrip : bool (optional)
True = field names and string values are stripped.
False = field names and string values are not stripped.
i_flds : list, int or None (optional)
The index number(s) of the field(s) to be read.
If i_flds is None or an empty list all fields are read.
formats : list/tuple, dtype or None (optional)
The formats (dtypes) used for the fields. These overrule the dtypes automatically applied by numpy.
If formats is a list containing less dtypes than the number of fields the last dtype is repeated for the remaining fields.
If formats is a single dtype this is used for all fields.
n_header : int (optional)
Number of header lines. The field names are expected to be in the last line of the header.
recarr2ndarr : bool (optional)
True = the result is returned as a numpy ndarray instead of a numpy recarray. If i_flds is a single integer the result will be 1-dimensional instead of 2-dimensional.
False = the result is returned as numpy recarray.
Returns: result : numpy recarray or ndarray
If recarr2ndarr is False the data is returned as numpy recarray.
If recarr2ndarr is True the data is returned as numpy ndarray. If i_flds is specified as a single integer the resulting ndarray is 1-dimensional; otherwise it is 2-dimensional.
-
table_func.
xls2arr
(f_xls, sheet=0, n_header=1, l_flds=None, fld_str=None, date2datetime64=True, datablock=None)¶ Function to read a table from a worksheet in an Excel workbook.
Parameters: f_xls : str
Excel file name.
sheet : int or str (optional)
Sheet index number or sheet name.
n_header : int (optional)
Number of header lines. The field names are expected to be in the last line of the header.
Note that empty rows are always ignored; n_header is counted from the first non-empty row.
l_flds : list or None (optional)
List of field names to read. If l_flds is None all fields are read.
fld_str : str or None (optional)
An arbitrary string which is scanned for occurences of field names. Occuring field names will be included in the list of fields to be read.
Such a string could originate from user input, e.g. a condition string which is specified in an input file for a tool.
date2datetime64 : bool (optional)
True = convert Excel dates to numpy datetime64 dtype.
False = do not convert Excel dates to numpy datetime64 dtype; dates are returned as strings in the format ‘YYYY-MM-DD hh:mm:ss’.
datablock : list or None (optional)
Data block: [irow_start,irow_end,icol_start,icol_end].
The indices may be None, which means that default values are used: 0 for irow_start and icol_start, nrow and ncol for irow_end and icol_end.
The indices irow_end and icol_end may be negative, which means that they are counted backward from nrow and ncol.
Returns: result : numpy recarray
See also
-
table_func.
xls2arr_allsheets
(f_xls, skip_empty_sheets=True, n_header=1, l_flds=None, fld_str=None, date2datetime64=True, datablock=None)¶ Function to read the tables from all worksheets in an Excel workbook.
Parameters: f_xls : str
Excel file name.
skip_empty_sheets : bool (optional)
Option to skip empty worksheets in the workbook.
n_header : int (optional)
Number of header lines. The field names are expected to be in the last line of the header.
Note that empty rows are always ignored; n_header is counted from the first non-empty row.
l_flds : list or None (optional)
List of field names to read. If l_flds is None all fields are read.
fld_str : str or None (optional)
An arbitrary string which is scanned for occurences of field names. Occuring field names will be included in the list of fields to be read.
Such a string could originate from user input, e.g. a condition string which is specified in an input file for a tool.
date2datetime64 : bool (optional)
True = convert Excel dates to numpy datetime64 dtype.
False = do not convert Excel dates to numpy datetime64 dtype; dates are returned as strings.
datablock : list or None (optional)
Data block: [irow_start,irow_end,icol_start,icol_end].
The indices may be None, which means that default values are used: 0 for irow_start and icol_start, nrow and ncol for irow_end and icol_end.
The indices irow_end and icol_end may be negative, which means that they are counted backward from nrow and ncol.
Returns: result : list
List containing a numpy recarray for each table.
sheets : list
List of corresponding worksheet names.
See also
-
table_func.
xls2fields
(f_xls, sheet=0, n_header=1, return_irowcol=False, datablock=None)¶ Function to get the field names of a table in a worksheet in an Excel workbook.
Parameters: f_xls : str
Excel file name.
sheet : int or str (optional)
Sheet index number or sheet name.
n_header : int (optional)
Number of header lines. The field names are expected to be in the last line of the header.
Note that empty rows are always ignored; n_header is counted from the first non-empty row.
return_irowcol : bool (optional)
Option to return the row and column indices of the table.
datablock : list or None (optional)
Data block: [irow_start,irow_end,icol_start,icol_end].
The indices may be None, which means that default values are used: 0 for irow_start and icol_start, nrow and ncol for irow_end and icol_end.
The indices irow_end and icol_end may be negative, which means that they are counted backward from nrow and ncol.
Returns: fields : list
List of field names.
irow : list
List of row indices.
Only return if return_irowcol is True. irow includes the header of the table.
icol : list
List of column indices.
Only return if return_irowcol is True.
-
table_func.
xls2sheets
(f_xls)¶ Function to get the worksheet names of an Excel workbook.
Parameters: f_xls : str
Excel file name.
Returns: sheets : list
List of sheet names