title: Convert a .sav file to .csv file in Python
body: <p>I want to convert the contents of *.sav file into a *.csv file in Python. I have written the following lines of code to access the details of variables in *.sav file. Now, I am not clear on how I can write the accessed variable data to a .csv file with headers</p>
  
  <pre><code>import scipy.io as spio
  on2file = 'ON2_2015_112m_220415.sav'
  on2data = spio.readsav(on2file, python_dict=True, verbose=True)
  </code></pre>
  
  <p>Following is the result when I run the above lines of the code:</p>
  
  <pre><code>IDL Save file is compressed
   -&gt; expanding to /var/folders/z4/r3844ql123jgkq1ztdr4jxrm0000gn/T/tmpVE_Iz6.sav
  --------------------------------------------------
  Date: Mon Feb 15 20:41:02 2016
  User: zhangy1
  Host: augur
  --------------------------------------------------
  Format: 9
  Architecture: x86_64
  Operating System: linux
  IDL Version: 7.0
  --------------------------------------------------
  Successfully read 11 records of which:
   - 7 are of type VARIABLE
   - 1 are of type TIMESTAMP
   - 1 are of type NOTICE
   - 1 are of type VERSION
  --------------------------------------------------
  Available variables:
   - saved_data [&lt;class 'numpy.recarray'&gt;]
   - on2_grid_smooth [&lt;type 'numpy.ndarray'&gt;]
   - d_lat [&lt;type 'numpy.float32'&gt;]
   - on2_grid [&lt;type 'numpy.ndarray'&gt;]
   - doy [&lt;type 'str'&gt;]
   - year [&lt;type 'str'&gt;]
   - d_lon [&lt;type 'numpy.float32'&gt;]
  --------------------------------------------------
  </code></pre>
  
  <p>Can anyone suggest me with how I can write all the variable data to a .csv file?</p>
  
  <p>I want to write the variables (year, doy, d_lon, d_lat, on2_grid, on2_grid_smooth) to a CSV or ASCII file is supposed to look in the following manner: </p>
  
  <pre><code>longitude, latitude, on2_grid, on2_grid_smooth   # header 
  0.0,0.0,0.0,0.0              
  0.0,0.0,0.0,0.0 
  0.0,0.0,0.0,0.0 
  0.0,0.0,0.0,0.0
  ..... 
  </code></pre>
  
  <p>The shape of "on2_grid" and "on2_grid_smooth" variables is the same and is (101, 202). Both are of the type "numpy.ndarray".</p>