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.

I want to get a dataframe indexed by tnr, the threshold that matches this tnr, for each class. Essentially, I want this:

I can achieve this effect using the following:
pd.concat([pd.Series(data[0].index.values, index=data[0]), pd.Series(data[1].index.values, index=data[1])], axis=1)
Or, generalizing to any number of columns:
def invert_dataframe(df): return pd.concat([pd.Series(df[col].index.values, index=df[col]) for col in df.columns], axis=1)
However, this seems extremely hacked and error prone. Is there a better way to do this, and maybe there is native Pandas functionality that will do this?
source share