title: How to swap index and values on pandas dataframe
body: <p>I have some data, in which the index is a threshold, and the values are trns (true negative rates) for two classes, 0 and 1. </p>
  
  <p><a href="https://i.stack.imgur.com/72Z8Q.png" rel="noreferrer"><img src="https://i.stack.imgur.com/72Z8Q.png" alt="enter image description here"></a></p>
  
  <p>I want to get a dataframe, indexed by the tnr, of the threshold that corresponds to that tnr, for each class. Essentially, I want this: </p>
  
  <p><a href="https://i.stack.imgur.com/AigE0.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AigE0.png" alt="enter image description here"></a></p>
  
  <p>I am able to achieve this effect by using the following: </p>
  
  <pre><code>pd.concat([pd.Series(data[0].index.values, index=data[0]), 
             pd.Series(data[1].index.values, index=data[1])], 
             axis=1)
  </code></pre>
  
  <p>Or, generalizing to any number of columns: </p>
  
  <pre><code>def invert_dataframe(df): 
      return pd.concat([pd.Series(df[col].index.values, 
                       index=df[col]) for col in df.columns], 
                       axis=1)
  </code></pre>
  
  <p>However, this seems extremely hacky and error prone. Is there a better way to do this, and is there maybe native Pandas functionality that would do this?</p>