title: How to save a whole pandas dataframe in text file
body: <p>Here is my code to save several pandas dataframe with some description  into a text file:</p>
  
  <pre><code>    import numy as np
      import pandas as pd
      rows=['row1','row2','row3', 'row4']
      data=np.random.randn(18, 4,3)
      with open(filename, "wb") as outfile:
           house_num = 0
           outfile.write(('Shape of house Array: {0}    \n'.format(data.shape)).encode())
           for data_slice in data:
               outfile.write(('@ House: {0} \n'.format(house_num)).encode())
               df=pd.DataFrame(data_slice,columns=list('XYZ'),dtype=float)
               df=df.rename(index={j:k for k, j in zip(rows,range(0,4))})
               text=df.to_string()
               np.savetxt(filename, text)
               house_num+=1
  </code></pre>
  
  <p>in the last line , I get an error <code>IndexError: tuple index out of range</code></p>
  
  <p>I want to get a text file formatting like this:</p>
  
  <pre><code>Shape of house Array: (18,4,3)
  house: 0
               X         Y         Z
  row1  1.376328  0.620332 -0.726298
  row2 -0.671292  0.557585 -0.027483
  row3  0.381491  1.798442  0.221806
  row4 -0.223592 -0.297638 -0.258627
  house: 1
               X         Y         Z
  row1  1.376328  0.620332 -0.726298
  row2 -0.671292  0.557585 -0.027483
  row3  0.381491  1.798442  0.221806
  row4 -0.223592 -0.297638 -0.258627
  ....
  
  house: 18
               X         Y         Z
  row1  1.376328  0.620332 -0.726298
  row2 -0.671292  0.557585 -0.027483
  row3  0.381491  1.798442  0.221806
  row4 -0.223592 -0.297638 -0.258627
  </code></pre>