title: Pandas to_csv drops rows (when writing to file-like object)
body: <p>When using a <code>tempfile.TemporaryFile</code> as an intermediate to writing a pandas DF to csv (<code>to_csv</code>), some rows are silently dropped from the end of the DF.
  The number of rows that is dropped depends on both the length and width of the DF, in a seemingly unpredictable manner. </p>
  
  <p>Indeed, if the DF is short enough, ALL rows are dropped and an empty file results (no rows written to disk).</p>
  
  <p>The evidence suggests that this is a bug in Pandas, but it is possible that I have an error in the pure Python code.</p>
  
  <p>See code and results below (python 3.5, pandas 0.20</p>
  
  <pre><code>import shutil
  from io import TextIOWrapper, BufferedWriter
  from tempfile import TemporaryFile
  import pandas as pd
  
  def pd_bug(size, rep_str):
      out_path = "bug_{}_{}".format(rep_str, size)
  
      diags = {"str": [rep_str] * size, "num": [i for i in range(size)]}
      df = pd.DataFrame(diags)
  
      with TemporaryFile() as f, BufferedWriter(f) as bw, TextIOWrapper(bw) as iow:
          df.to_csv(iow, index=False)
          with open(out_path, "w+b") as t:
                  f.seek(0)
                  shutil.copyfileobj(f, t)
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>pd_bug(100, "abc")      # tail -n1 bug_abc_100      -&gt;                &lt;EMPTY&gt;
  pd_bug(1000, "abc")     # tail -n1 bug_abc_1000     -&gt;                &lt;EMPTY&gt;
  pd_bug(2000, "abc")     # tail -n1 bug_abc_2000     -&gt;  1943,abc      &lt;57 dropped&gt;
  pd_bug(5000, "abc")     # tail -n1 bug_abc_5000     -&gt;  4676,abc      &lt;324 dropped&gt;
  pd_bug(10000, "abc")    # tail -n1 bug_abc_10000    -&gt;  9231,abc      &lt;769 dropped&gt;
  pd_bug(50000, "abc")    # tail -n1 bug_abc_50000    -&gt;  49488,abc     &lt;512 dropped&gt;
  
  pd_bug(100, "pandas")   # tail -n1 bug_pandas_100   -&gt;                &lt;EMPTY&gt;
  pd_bug(1000, "pandas")  # tail -n1 bug_pandas_1000  -&gt;  754,pandas    &lt;46 dropped&gt;
  pd_bug(2000, "pandas")  # tail -n1 bug_pandas_2000  -&gt;  1458,pandas   &lt;542 dropped&gt;
  pd_bug(5000, "pandas")  # tail -n1 bug_pandas_5000  -&gt;  4873,pandas   &lt;127 dropped&gt;
  pd_bug(10000, "pandas") # tail -n1 bug_pandas_10000 -&gt;  9654,pandas   &lt;346 dropped&gt;
  pd_bug(50000, "pandas") # tail -n1 bug_pandas_50000 -&gt;  49433,pandas  &lt;567 dropped&gt;
  </code></pre>
  
  <p>This only seems to occur using the file-like object; using the standard
  <code>df.to_csv("/a/path/ok")</code> works fine -- no rows are dropped</p>