title: Python pandas to_csv causes OSError: [Errno 22] Invalid argument
body: <p>My code is the following: </p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  df = pd.read_csv("path/to/my/infile.csv")
  df = df.sort_values(['distance', 'time'])
  df.to_csv("path/to/my/outfile.csv")
  </code></pre>
  
  <p>this code reads from infile.csv which is a 3GB csv file successfully, sorts it and fails when trying to write to outfile.csv with the following error:</p>
  
  <pre><code>OSError                                   Traceback (most recent call last)
  &lt;ipython-input-10-3a5c8279658d&gt; in &lt;module&gt;
  ----&gt; 1 df.to_csv('/Users/joaomatos/Desktop/cluster22_sorted_training.csv',index=False)
  
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/frame.py in to_csv(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, compression, quoting, quotechar, line_terminator, chunksize, tupleize_cols, date_format, doublequote, escapechar, decimal)
     1743                                  doublequote=doublequote,
     1744                                  escapechar=escapechar, decimal=decimal)
  -&gt; 1745         formatter.save()
     1746 
     1747         if path_or_buf is None:
  
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/formats/csvs.py in save(self)
      164                                          encoding=encoding,
      165                                          compression=self.compression)
  --&gt; 166                 f.write(buf)
      167                 f.close()
      168                 for _fh in handles:
  
  OSError: [Errno 22] Invalid argument
  </code></pre>
  
  <p>My question is why?</p>
  
  <p>Thank you for your help</p>