I have a df as below - what I want to do is to convert 1 to 0 if ONLY the column names are equal to row names.
print(df)
name seq102681 seq103 seq11
0 seq102681 1 0 0
1 seq103 0 1 0
2 seq11 1 1 1
the desired output should be:
name seq102681 seq103 seq11
0 seq102681 0 0 0
1 seq103 0 0 0
2 seq11 1 1 0
I tried using intersection but it does not work.
import pandas as pd
df = pd.read_csv('file.csv')
intersection = df.index & df.columns
for item in intersection:
df.loc[item, item] = 0
print(df)
Note: there are sometimes multiple rows with the same name but all of the column names are unique.
Thank you.