.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_data_analysis/manage_data_and_samples/plot_import_export_sample_csv.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_data_analysis_manage_data_and_samples_plot_import_export_sample_csv.py: Import / export a sample via a CSV file ======================================= .. GENERATED FROM PYTHON SOURCE LINES 6-7 In this example we are going to import and export a data sample from/to a CSV file. .. GENERATED FROM PYTHON SOURCE LINES 9-12 .. code-block:: default import openturns as ot ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 13-14 create a sample from a 2-d gaussian distribution .. GENERATED FROM PYTHON SOURCE LINES 14-17 .. code-block:: default sample = ot.Normal(2).getSample(5) sample.setDescription(['u1', 'u2']) .. GENERATED FROM PYTHON SOURCE LINES 18-20 write a CSV file warning the default separator is ';' .. GENERATED FROM PYTHON SOURCE LINES 20-22 .. code-block:: default sample.exportToCSVFile('sample.csv', ',') .. GENERATED FROM PYTHON SOURCE LINES 23-24 print the content of the written file .. GENERATED FROM PYTHON SOURCE LINES 24-28 .. code-block:: default with open('sample.csv', 'r') as f: for line in f.readlines(): print(line, end='') .. rst-class:: sphx-glr-script-out Out: .. code-block:: none "u1","u2" -5.9371883900074729e-01,1.4041106332197137e+00 3.8619059669064060e-01,-1.3181109089520018e+00 9.6132882982427406e-02,-7.5281659912741927e-01 2.5792642458131404e-01,1.9687596027732095e+00 -6.7129053308146580e-01,1.8557922404430598e+00 .. GENERATED FROM PYTHON SOURCE LINES 29-30 read the previous CSV file .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: default sample = ot.Sample.ImportFromCSVFile('sample.csv', ',') print(sample) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [ u1 u2 ] 0 : [ -0.593719 1.40411 ] 1 : [ 0.386191 -1.31811 ] 2 : [ 0.0961329 -0.752817 ] 3 : [ 0.257926 1.96876 ] 4 : [ -0.671291 1.85579 ] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.002 seconds) .. _sphx_glr_download_auto_data_analysis_manage_data_and_samples_plot_import_export_sample_csv.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_import_export_sample_csv.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_import_export_sample_csv.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_