Export a sample to a CSV fileΒΆ

In this basic example we are going to export a sample to a CSV file.

In [26]:
from __future__ import print_function
import openturns as ot

# create a sample from a 2-d gaussian distribution
sample = ot.Normal(2).getSample(5)
sample.setDescription(['u1', 'u2'])
In [27]:
# default separator is ';'
sample.exportToCSVFile('sample.csv', ',')
In [28]:
# print the content of the file
with open('sample.csv', 'r') as f:
    for line in f.readlines():
        print(line, end='')
"u1","u2"
3.3156880087779661e-01,-4.8820474790372442e-01
-4.6548206392049335e-01,3.3208385645183086e-01
-1.6772582180258397e-01,3.0126267437025929e+00
9.4204049100015808e-01,6.1189014041922474e-01
6.1171515642720731e-01,-1.5374973590145564e+00