algebraixlib.io.csv module¶
Import regular clans from and export them to CSV data.
-
algebraixlib.io.csv.
export_csv
(absolute_clan: 'PP(A x A)', file_or_path, ordered_lefts=None, sort_key=None)[source]¶ Export a regular, absolute clan as CSV file with header row.
The left components of the clan are interpreted as column names and are exported as header row. Every relation in the clan becomes a data row in the CSV file.
Parameters: - absolute_clan – A regular, absolute clan.
- 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 clan. - 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,Undef()
if not.
-
algebraixlib.io.csv.
import_csv
(csv_file_or_filepath, types=None, skip_rows=0, index_column=None, has_dup_rows=False) → 'PP( A x M )'[source]¶ Import the file
csv_file_or_filepath
as CSV data and return a clan.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
.)
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