I have a dataframe called df1:
d = {'letter':['R','V','Q','M','F','K'], 'info1':['K:2.3','T:1.3','L:2.4','B:7.4','S:2.3','K:4.4'], 'info2':['R:3.2','N:2.1','B:0.3','T:0.9','J:0.003','S:1.223'], 'info3':['X:45','V:32.4','H:0.04','M:3.34','T:2.2','T:3.456'], 'info4':['A:1.7','Z:1.2345','T:9.5','O:3,2','J:3.334','G:345']}
df1 = pd.DataFrame(d)
df1:
letter info1 info2 info3 info4
0 R K:2.3 R:3.2 X:45 A:1.7
1 V T:1.3 N:2.1 V:32.4 Z:1.2345
2 Q L:2.4 B:0.3 H:0.04 T:9.5
3 M B:7.4 T:0.9 M:3.34 O:3,2
4 F S:2.3 J:0.003 T:2.2 J:3.334
5 K K:4.4 S:1.223 T:3.456 G:345
I want to partially match the strings in column "letter" with the occurrence of that string on the same row and place the match into a new column. If there is no match on the same row then I just want to put NaN.
Desired output:
letter info1 info2 info3 info4 new
0 R K:2.3 R:3.2 X:45 A:1.7 R:3.2
1 V T:1.3 N:2.1 V:32.4 Z:1.2345 V:32.4
2 Q L:2.4 B:0.3 H:0.04 T:9.5 NaN
3 M B:7.4 T:0.9 M:3.34 O:3,2 M:3.34
4 F S:2.3 J:0.003 T:2.2 J:3.334 NaN
5 K K:4.4 S:1.223 T:3.456 G:345 K:4.4
I initially tried creating a mask but that did not work.
df1['new'] = df1.drop("letter", 1).isin(df1["letter"]).any(1)
Any ideas would be great