votesim.utilities.write¶
Write tables to text.
Class Summary¶
|
Read file constructed using StringTable. |
|
Standardardized string table for file output. |
Function Summary¶
|
Construct empty string list for entry numbers of colnum |
|
format list of numbers to string. |
|
format list of numbers or strings to a delimited string. |
|
format a 2D numpy array to a list of strings |
|
Return list of column header names as numpy array |
|
Horizontally stack arrays where: |
|
Horizontally stack lists of string in the format of: |
|
Pad string1 to the requested number of delimiters. |
|
format a list and wrap by max number of columns |
Module Classes¶
ReadTable¶
-
class
votesim.utilities.write.
ReadTable
(f, labelrows=None, delimiter=',')¶ Read file constructed using StringTable.
All data is read as str and as numpy arrays. All data is indexed as both ether a numpy array or as a using keys found from the labels.
- Parameters
f (file-like or iterable) – file or iterable with text data
labelrows (list or None) – List of column row numbers that have column label information. By default, this is set to None to use only 0th row.
delimiter (str) – Table delimiter
Method/Attribute Summary¶
|
Find keyword within labels. |
-
ReadTable.
dict
()¶
-
ReadTable.
find
(key)¶ Find keyword within labels. Return columns with keyword
array of shape (a, b)
StringTable¶
-
class
votesim.utilities.write.
StringTable
(sfmt='%s', nfmt='%.8e', ifmt='%d', delimiter=',', header=None)¶ Standardardized string table for file output.
- Parameters
sfmt (str) – formatting specifier for string formatting, ex. ‘%16s’.
nfmt (str) – formatting specifier for numeric formatting, ex. ‘%16.8e’.
ifmt (str) – formatting specifier for integer formatting, ex. ‘%16d’.
delimiter (str) – specification for delimiter. Default is ‘,’.
Usage –
----- –
data using self.add (Add) –
data = [A x B] array of A rows of data and B columns (-) –
labels = [C x B] array-1d of labels for B columns. (-) –
A = # of data rows (-) –
B = # of data columns (-) –
C = # of column label rows (-) –
Add data using “add” method.
Method/Attribute Summary¶
|
Add data to table. |
|
Write data to file fname. |
|
Construct string data for table. |
Return number of columns |
-
StringTable.
add
(labels, data, fmt=None)¶ Add data to table.
- Parameters
data ([A, B] array) – A rows of data and B columns
labels ([C, B] array) – Labels for B columns.
fmt (str) – Formatting string. If None, use default number format self.nfmt
A = # of data rows (*) –
B = # of data columns (*) –
C = # of column label rows (*) –
-
StringTable.
write
(fname, headers=False, labels=True)¶ Write data to file fname. Can be file, path, or filelike.
-
StringTable.
string_lines
(headers=False, labels=True)¶ Construct string data for table.
-
StringTable.
colnum
()¶ Return number of columns
Module Functions¶
empty_table_str¶
-
votesim.utilities.write.
empty_table_str
(rows, columns, fmt='%16s', delimiter=',')¶ Construct empty string list for entry numbers of colnum
format_list¶
-
votesim.utilities.write.
format_list
(list1, fmt='%16s', delimiter=',')¶ format list of numbers to string. delimiter defaults = ‘,’
format_list2¶
-
votesim.utilities.write.
format_list2
(list1, sfmt='%16s', nfmt='%16.8e', delimiter=',')¶ format list of numbers or strings to a delimited string.
- Parameters
list1 (list of numbers and strings) – List to convert to string
sfmt (str) – string formatter, ie “%16s”
nfmt (str) – number format, ie ‘%16.8e’
delimiter (str) – list delimiter
format_narray¶
-
votesim.utilities.write.
format_narray
(narray, fmt='%16s', delimiter=',')¶ format a 2D numpy array to a list of strings
get_header_names¶
-
votesim.utilities.write.
get_header_names
(fname, row_num, delimiter=None)¶ Return list of column header names as numpy array
hstack_arrays¶
-
votesim.utilities.write.
hstack_arrays
(arrays, sfmt='%16s', nfmt='%16.8e', delimiter=',')¶ Horizontally stack arrays where:
- Parameters
arrays (list/iterable) – Array-like objects
sfmt (str) – String format (ex, ‘%16s’)
nfmt (str) – number format (ex, ‘%16.8e’)
delimiter (str) – Delimiter for columns
- Returns
slist
- Return type
list of string lines
hstack_str_list¶
-
votesim.utilities.write.
hstack_str_list
(str_lists, delimiter=',', pad=False)¶ - Horizontally stack lists of string in the format of:
str_lists = [strlist1, strlist2, strlist3, …] strlisti = list of strings similar to output to file.readlines()
Prepare the strings for write to file, add new lines.
- Parameters
str_lists (list of list of str) – Multiple lists of strings, each list to be horizontally stacked.
delimiter (str) – Delimiter
- Returns
out
- Return type
list of str
pad_delimiters¶
-
votesim.utilities.write.
pad_delimiters
(string1, number, delimiter=',', slen=None)¶ Pad string1 to the requested number of delimiters.
- Parameters
string1 (str) – String to be assessed
number (int) – Number of total delimiters in final output string
delimiter (str) – String type of delimiter to use