title: How to get a table in a format using pandas and export to csv?
body: <p>I am new to pandas .I want the a table in a format which I need to export csv.</p>
  
  <p>What I have tried is:</p>
  
  <p>o_rg,o_gg,a_rg,a_gg are arrays</p>
  
  <pre><code>  df1=pd.DataFrame({'RED':o_rg,'GREEN':o_gg})
    df2=pd.DataFrame({'RED':a_rg,'RED':a_gg})
    df=df1-(df2)
    pop_complete = pd.concat([df, df1, df2], keys=["O-A", "O", "A"], axis=1)
    pop_complete.index = ['A1','A3','A8']
    df1 = pop_complete.stack(0)[['RED','GREEN']].reindex(["O", "A", "O-A"], axis=0, level=1)
    df1.to_csv("OUT.CSV")
  </code></pre>
  
  <p>What I get the output as:</p>
  
  <pre><code>       RED     GREEN       
  
      A1 O        14.0     14.0
         A        14.0     12.0
         O-A      0.0      2.0
  
      A3 O        12.0     9.0
         A        12.0     10.0
         O-A      0.0      -1.0
  
      A8 O        15.0     12.0
         A        15.0     12.0
         O-A      0.0      0.0
  </code></pre>
  
  <p>What I actually want is:</p>
  
  <pre><code>                RED     GREEN       
         A1
         O        14.0     14.0
         A        14.0     12.0
         O-A      0.0      2.0
         A3
         O        12.0     9.0
         A        12.0     10.0
         O-A      0.0      -1.0
         A8
         O        15.0     12.0
         A        15.0     12.0
         O-A      0.0      0.0
  </code></pre>
  
  <p>where 'A1','A3','A8' ... can be stored in array cases=[]
  How to get the actual output?</p>