I have a data frame:
d1 ={'letters':['ABCDE[NOT]FGH', 'CCGF[NOT]HI', 'MPJ[NOT]L', 'MNA[NOT]PLJKAJSHD']}
df1 = pd.DataFrame(d1)
df1:
letters
0 ABCDE[NOT]FGH
1 CCGF[NOT]HI
2 MPJ[NOT]L
3 MNA[NOT]PLJKAJSHD
I want to create a space between each character except for those between the [ ].
Desired output:
letters
0 A B C D E [NOT] F G H
1 C C G F [NOT] H I
2 M P J [NOT] L
3 M N A [NOT] P L J K A J S H D
I have tried:
matching = re.sub(r'[^a-zA-Z []]+(?![^{]*})(\w)', r'\1', i)
df1['letters'].apply(lambda x: matching)
But this does not seem to work. any ideas?