CsvWriteOptions(separator=',', encoding=Encoding.UTF_8, decimals=None)
Source¶
Settings of a CSV file written by Table.to_csv.
Added in version 0.1.0
Parameters:
-
separator(str, default:',')The character between two values of a row,
","by default. -
encoding(Encoding, default:Encoding.UTF_8)The text encoding of the file, UTF-8 by default.
-
decimals(int | None, default:None)The number of decimals written for every decimal column, 0 or more. Each value is rounded and keeps its zeros, such as
1.50, so the file no longer holds the exact values. When omitted, a decimal is written with every digit of its value.
Raises:
-
InvalidTypeErrorWhen a setting is not of the type its annotation names.
-
InvalidSeparatorErrorWhen the separator is not exactly one character.
-
InvalidCountErrorWhen
decimalsis negative.
Examples:
import tempfile
from pathlib import Path
import numdaplot as ndp
path = Path(tempfile.mkdtemp()) / "sales.csv"
prices = ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5, 8.0])})
prices.to_csv(path, ndp.CsvWriteOptions(separator=";", decimals=2))
print(path.read_text())
# price
# 1.50
# 8.00
#