I want to mask out the values in a Pandas DataFrame where the index is the same as the column name. For example:
import pandas as pd
import numpy as np
a = pd.DataFrame(np.arange(12).reshape((4, 3)),
index=["a", "b", "c", "d"],
columns=["a", "b", "c"])
a b c
a 0 1 2
b 3 4 5
c 6 7 8
d 9 10 11
After masking:
a b c
a NaN 1 2
b 3 NaN 5
c 6 7 NaN
d 9 10 11
Seems simple enough but I'm not sure how to do it in a Pythonic way, without iteration.