larray.LArray.to_csv

LArray.to_csv(filepath, sep=', ', na_rep='', transpose=True, dropna=None, dialect='default', **kwargs)[source]

Writes array to a csv file.

Parameters:

filepath : str

path where the csv file has to be written.

sep : str

seperator for the csv file.

na_rep : str

replace NA values with na_rep.

transpose : boolean

transpose = True => transpose over last axis. transpose = False => no transpose.

dialect : ‘default’ | ‘classic’

Whether or not to write the last axis name (using ‘’ )

dropna : None, ‘all’, ‘any’ or True, optional

Drop lines if ‘all’ its values are NA, if ‘any’ value is NA or do not drop any line (default). True is equivalent to ‘all’.

Examples

>>> from larray.tests.common import abspath
>>> fpath = abspath('test.csv')
>>> a = ndrange('nat=BE,FO;sex=M,F')
>>> a
nat\sex  M  F
     BE  0  1
     FO  2  3
>>> a.to_csv(fpath)
>>> with open(fpath) as f:
...     print(f.read().strip())
nat\sex,M,F
BE,0,1
FO,2,3
>>> a.to_csv(fpath, sep=';', transpose=False)
>>> with open(fpath) as f:
...     print(f.read().strip())
nat;sex;0
BE;M;0
BE;F;1
FO;M;2
FO;F;3
>>> a.to_csv(fpath, dialect='classic')
>>> with open(fpath) as f:
...     print(f.read().strip())
nat,M,F
BE,0,1
FO,2,3