CsvReadOptions(separator=',', encoding=Encoding.UTF_8, column_names=ColumnNames.CLEANED, missing_texts=None)
Source¶
Settings of a CSV file read by Table.from_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.
-
column_names(ColumnNames, default:ColumnNames.CLEANED)Whether the column names are cleaned,
ColumnNames.CLEANEDby default: the spaces, tabs and line breaks at the start and the end of each name are removed.ColumnNames.KEPTkeeps the names as written. -
missing_texts(list[str] | None, default:None)The texts read as missing values, compared with the whole value of each cell. When omitted, the texts pandas reads as missing:
"","#N/A","#N/A N/A","#NA","-1.#IND","-1.#QNAN","-NaN","-nan","1.#IND","1.#QNAN","<NA>","N/A","NA","NULL","NaN","None","n/a","nan"and"null". A given list replaces them:[]reads no value as missing, not even an empty one, so a column of numbers with an empty value is read as texts.
Raises:
-
InvalidTypeErrorWhen a setting is not of the type its annotation names.
-
InvalidSeparatorErrorWhen the separator is not exactly one character.
Examples:
import tempfile
from pathlib import Path
import numdaplot as ndp
path = Path(tempfile.mkdtemp()) / "sales.csv"
_ = path.write_text("city;price\nParis;1.5\nLyon;8.0\n")
ndp.Table.from_csv(path, ndp.CsvReadOptions(separator=";"))
# city price
# TEXT FLOAT64
# 0 Paris 1.5
# 1 Lyon 8.0
_ = path.write_text("city;code\nParis;N/A\nLyon;\n")
ndp.Table.from_csv(path, ndp.CsvReadOptions(separator=";", missing_texts=[""]))
# city code
# TEXT TEXT
# 0 Paris N/A
# 1 Lyon <NA>