bebi103.utils.unpivot_csv
- bebi103.utils.unpivot_csv(input_file: str, output_file: str, n_header_rows=None, header_names=None, value_name: str = 'value', sep: str = ',', retain_row_index: bool = True, row_index_name: str = 'original_row_index', comment_prefix=None, force_overwrite=False, include_comments=True, additional_comment=None) None
Converts a CSV file in wide format, possibly with a hierarchical column, index to tall format via a unpivot operation.
- Parameters:
input_file (str) – Path to CSV file containing data in a wide format.
output_file (str) – Path to file to write contents in tall format.
n_header_rows (int, default 1) – Number of header rows, ignored if header_names is given.
header_names (string, list of strings, or None, default None) – Names of each level of the header. These become the names of columns in the tall representation of the data set. If None, column names are variable_0, variable_1, etc.
value_name (str or None, default 'value') – Name to assign to column containing values in tall representation.
sep (str, default ',') – Separator. Cannot be a regex; must be a single character.
retain_row_index (bool, default True) – If True, include a column containing the original row index in the original file. This is useful to avoid information loss, since all entries in a given row can be related. These are essentially identifies variables.
row_index_name (str, default 'original_row_index') – Label in the row index if the row index is retained. Ignored if retain_row_index is False.
comment_prefix (str or None, default None) – A single character defining which rows in the input file should be treated as comments.
force_overwrite (bool, default False) – If True, if the output_file already exists, it is overwritten.
include_comments (bool, default True) – If True, write comments from the input file in the output files.
additional_comment (str or None, default None) – Additional comment at top of output file.
- Returns:
output – Does not return anything. The output is written to output_file.
- Return type:
None