larray.read_csv¶
-
larray.read_csv(filepath_or_buffer, nb_index=None, index_col=None, sep=', ', headersep=None, fill_value=nan, na=nan, sort_rows=False, sort_columns=False, dialect='larray', **kwargs)[source]¶ Reads csv file and returns an array with the contents.
Parameters: filepath_or_buffer : str or any file-like object
Path where the csv file has to be read or a file handle.
nb_index : int, optional
Number of leading index columns (ex. 4).
index_col : list, optional
List of columns for the index (ex. [0, 1, 2, 3]).
sep : str, optional
Separator.
headersep : str or None, optional
Separator for headers.
fill_value : scalar or LArray, optional
Value used to fill cells corresponding to label combinations which are not present in the input. Defaults to NaN.
sort_rows : bool, optional
Whether or not to sort the rows alphabetically (sorting is more efficient than not sorting). Defaults to False.
sort_columns : bool, optional
Whether or not to sort the columns alphabetically (sorting is more efficient than not sorting). Defaults to False.
dialect : ‘classic’ | ‘larray’ | ‘liam2’, optional
Name of dialect. Defaults to ‘larray’.
**kwargs
Returns: LArray
Notes
csv file format: arr,ages,sex,nat ime,1991,1992,1993 A1,BI,H,BE,1,0,0 A1,BI,H,FO,2,0,0 A1,BI,F,BE,0,0,1 A1,BI,F,FO,0,0,0 A1,A0,H,BE,0,0,0
Examples
>>> from larray.tests.common import abspath >>> from larray import ndrange >>> fpath = abspath('test.csv') >>> a = ndrange('nat=BE,FO;sex=M,F')
>>> a.to_csv(fpath) >>> read_csv(fpath) nat\sex M F BE 0 1 FO 2 3 >>> read_csv(fpath, sort_columns=True) nat\sex F M BE 1 0 FO 3 2 >>> fpath = abspath('no_axis_name.csv') >>> a.to_csv(fpath, dialect='classic') >>> read_csv(fpath, nb_index=1) nat\{1} M F BE 0 1 FO 2 3