Question: I have a dataframe in a "yes/no" format like

```
    7   22
1   NaN t
25  t   NaN

```

where "t" stands for yes and I need to transform it to a X-Y table since the column name is the X coordinate and the index is the Y coordinate:

```
  X  Y
1 22  1
2  7 25

```

a pseudo-code like:

```
if a cell = "t":
     newdf.X = df.column(t)
     newdf.Y = df.index(t)

```

Answer: 
Another option with `stack`:

```
pd.DataFrame.from_records(
    df.stack().index.swaplevel(),
    columns=['X', 'Y'])

```

Output:

```
    X   Y
0  22   1
1   7  25

```
Based on the magic of stacking, my answer is a tweak of @Perl's [answer](https://stackoverflow.com/users/12399409/kristian-canler) (couldn't comment because reps < 50)-

```
df.stack().to_frame().reset_index().drop(0,axis = 1).rename(columns = {'level_0':"Y","level_1":"X"}).reindex(columns=["X","Y"])

```

*PS - Thanks [Kristian Canler](https://stackoverflow.com/users/12399409/kristian-canler) for the edit.*