I have a df that looks like this:
Column A | Column B | Column C | Column D |
---|---|---|---|
Cell 1 | Cell 6 | Cell 8 | Cell 4 |
Cell 2 | Cell 7 | Cell 9 | Nan |
Cell 3 | Nan | Cell 10 | Nan |
Cell 4 | Nan | Nan | Nan |
Cell 5 | Nan | Nan | Nan |
I'm trying to build a function such as the entry is any value in the df, and the output is the column to which the value belongs to.
My ideia would be doing something like
df[df == val].stack().index[0][1]
It does work, but it is a little to slow after a loot of iterations. If you people know any other, faster way to get the same result, it would be much apretiated.
The df I am working with isn't much larger than this one. it's shape is (21, 16), maybe if I store it like a dict or something it would be better.
Please, any input would be apretiated.