Quantcast
Channel: How to retrieve row and column names from data frame? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How to retrieve row and column names from data frame?

$
0
0

I have generated a correlation matrix from a dataframe using pandas.corr:

cmat = sub1.corr()cmatOut[75]:           CESI001   CESI002   CESI003   CESI004CESI001  1.000000  0.829723  0.046925  0.074475CESI002  0.829723  1.000000  0.066766  0.073181CESI003  0.046925  0.066766  1.000000 -0.098427CESI004  0.074475  0.073181 -0.098427  1.000000

What I'm trying to do is generate a new dataframe consisting of [row, column, value] where the cell value meets some criteria. I have succeeded in retrieving the matching cell values:

for i2,r2 in cmat.iterrows():for item in cmat[i2]:    if ((item > 0.3) and (item < 0.9)):        print (item)

This correctly produces:

0.8297233650190.829723365019

However, I can't work backwards from there to retrieve the row and column names. I've tried .loc, .columname and several other approaches I read about here. I'm getting that Python is more about operating on the whole data frame. Any guidance appreciated.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images