algebraixlib.import_export.csv module¶
Import regular clans from and export them to CSV data.
-
algebraixlib.import_export.csv.
export_csv
(absolute_clan_or_multiclan, file_or_path, ordered_lefts=None, sort_key=None)[source]¶ Export an absolute clan or absolute multiclan as CSV file with header row.
The left components of the clan or term:
multiclan
are interpreted as column names and are exported as header row. Every relation in the input becomes a data row in the CSV file.Parameters: - absolute_clan_or_multiclan – An absolute clan or term:
absolute multiclan
. If it is not regular,ordered_lefts
must be given. - file_or_path – Either a file path (in this case the CSV data is written to a file at this
location) or a file object (in this case the CSV data is written to its
.write()
function). - ordered_lefts – (Optional) A
Sequence
of lefts that are exported in the given order. Default is the sequence that is the lexically sorted left set of the (multi)clan. This parameter is required ifabsolute_clan_or_multiclan
is not term:regular
. - sort_key – (Optional) A function that compares two row-relations and provides an
order (for use with
sorted()
). The output is not sorted ifsort_key
is missing.
Returns: True
if the CSV export succeeded,False
if not.- absolute_clan_or_multiclan – An absolute clan or term:
-
algebraixlib.import_export.csv.
import_csv
()[source]¶ Import the file
csv_file_or_filepath
as CSV data and return a clan or multiclan.Parameters: - csv_file_or_filepath – The file path or file object (for example
StringIO
buffer) to import. - types – (Optional) A dictionary of type conversions. The keys are the column names; the
values are functors (or types) that receive the string from the CSV cell and return the
value to be imported. Example:
{'foo': int, 'bar': float}
. By default all values are interpreted asstring
s. - skip_rows – (Optional) A number of lines to skip (default 0). Some CSV files have a preamble that can be skipped with this option.
- index_column – (Optional) A name for an index column. (No index column is created if this
argument is not specified.) The index starts with 0. (This option is not compatible with the
has_dup_rows
option.) - has_dup_rows – (Optional) If
True
, allow duplicate rows and return a multiclan instead of a clan. By default, the value isFalse
and a clan is returned. (This option is not compatible with the optionindex_column
.) - columns – (Optional) A list of column names. If present, this list is used as the sequence of columns (and all lines in the data are loaded). If missing, the first line of the data must be a header that contains the column names (and this header line is not loaded as data).
Returns: A clan (if
has_dup_rows is ``False
or not provided) or a multiclan (ifhas_dup_rows
isTrue
).- csv_file_or_filepath – The file path or file object (for example