{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Export a sample to a CSV file"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this basic example we are going to export a sample to a CSV file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "import openturns as ot\n",
    "\n",
    "# create a sample from a 2-d gaussian distribution\n",
    "sample = ot.Normal(2).getSample(5)\n",
    "sample.setDescription(['u1', 'u2'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# default separator is ';'\n",
    "sample.exportToCSVFile('sample.csv', ',')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"u1\",\"u2\"\n",
      "3.3156880087779661e-01,-4.8820474790372442e-01\n",
      "-4.6548206392049335e-01,3.3208385645183086e-01\n",
      "-1.6772582180258397e-01,3.0126267437025929e+00\n",
      "9.4204049100015808e-01,6.1189014041922474e-01\n",
      "6.1171515642720731e-01,-1.5374973590145564e+00\n"
     ]
    }
   ],
   "source": [
    "# print the content of the file\n",
    "with open('sample.csv', 'r') as f:\n",
    "    for line in f.readlines():\n",
    "        print(line, end='')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
