neuralib.io.csv_header.csv_header
- neuralib.io.csv_header.csv_header(output, header, append=False, buffer=False, continuous_mode=None, quotes_header=None)[source]
context manager for writing csv with given headers.
Example
>>> csv_output = Path('output.csv') >>> with csv_header(csv_output, ['neuron_id', 'data']) as csv: ... for neuron in range(total_neuron): ... csv(neuron, neuron + 1)
generate file output.csv with content:
neuron_id,data 0,1 1,2 2,3
continuous mode
>>> with csv_header(csv_output, ['neuron_id', 'data'], append=True, continuous_mode='neuron_id') as csv: ... for neuron in range(total_neuron): ... if neuron not in csv: ... csv(neuron, neuron + 1)
- Parameters:
output (str | Path | PathLike[str] | None) – output path
header (list[str]) – csv header list
append (bool) – if true, append in a same output csv file next time. otherwise, overwrite
buffer (bool) – buffering output if append mode
continuous_mode (str | None) – continuous append csv file with append mode. Give a field name which must be a member in the header.
quotes_header (list[str] | str | None) – list of header that need to use double quotes
- Returns:
row data consumer.
- Return type:
CsvContextManager