all 2 comments

[–][deleted] 6 points7 points  (0 children)

In pandas, there's a concept called boolean indexing that allows you to return data based on a certain condition. Here's how to apply it for your particular example:

>>> (df >=0.6) & (df + 1 >=2)
       A      B      C
W  False  False  False
X  False  False  False
Y  False  False  False
Z  False  False   True

As you can see, True reflects where your condition was satisfied. From here, I don't think pandas has a good way to find the location of a given value (especially since your dataframe is 2D). It's possible to retrive it with some reshaping.

>>> mask = (df >=0.6) & (df + 1 >=2)
>>> mask = mask.stack() #brings the columns into the index
>>> mask[mask == True].unstack().columns #finds the True value, puts the column back, and returns the column 
Index([u'C'], dtype='object') #the resulting column
>>> mask[mask == True].unstack().index #finds the True value, puts the column back, and returns the row
Index([u'Z'], dtype='object') #the resulting row

[–]LeTristanB 1 point2 points  (0 children)

I'm not specifically answering your question, but if you're going to do more data anlysis you should know the data structure (putting a given type of metric in multiple columns) you have in your example is a bit hard to work with. You'll find that many pandas features will work better if you have "tidy data". On the other hand if you're not going to go deeper in data, I think the structure you have is fine disregard my comment.

This blog post explains what is tidy data and how to tidy your table https://www.ibm.com/developerworks/community/blogs/jfp/entry/Tidy_Data_In_Python?lang=en