title: Unexpected behavior with open() and numpy.savetext() functions
body: <h1>Problem</h1>
  
  <p>I am trying to output statistics about a table, followed by more table data using Pandas and numpy.</p>
  
  <p>When I execute the following code:</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  data = pd.read_csv(r'c:\Documents\DS\CAStateBuildingMetrics.csv')
  
  waterUsage = data["Water Use (All Water Sources) (kgal)"]
  dept = data[["Department Name", "Property Id"]]
  mean = str(waterUsage.mean())
  median = str(waterUsage.median())
  most = str(waterUsage.mode())
  
  hw1 = open(r'c:\Documents\DS\testFile', "a")
  hw1.write("Mean Water Usage     Median Water Usage      Most Common Usage Amounts\n")
  hw1.write(mean+'       '+median+'                   '+most)
  np.savetxt(r'c:\Documents\DS\testFile', dept.values, fmt='%s')
  </code></pre>
  
  <p>The table output by np.savetext is written into <code>c:\Documents\DS\testFile</code> before the statistics about Mean, Median, and Mode water usage are written into the file. Below is the output I am describing:</p>
  
  <p>Here is a sample of the table output, which ends up to be 1700 rows. </p>
  
  <blockquote>
    <p>Capitol Area Development Authority 1259182<br>
    Capitol Area Development Authority 1259200<br>
    Capitol Area Development Authority 1259218<br>
    California Department of Forestry and Fire Protection 3939905<br>
    California Department of Forestry and Fire Protection 3939906<br>
    California Department of Forestry and Fire Protection 3939907</p>
  </blockquote>
  
  <p>After this, the script outputs the statistics in this format</p>
  
  <blockquote>
    <p>Mean Water Usage&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Median Water Usage&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Most Common Usage Amounts<br>
    6913.1633414932685&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;182.35&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;          0   165.0<br>
    Type: float64</p>
  </blockquote>
  
  <h1>Question</h1>
  
  <p>How do I adjust the behavior to guarantee that the statistics appear before the table?</p>