Вы можете использовать регулярное выражение с str.replace
:
s.str.replace(r'(\w+)\s+\(([^\)])\)', r'\1_ID_\2')
0 My_name_ID_1
1 Your_name_ID_2
Name: 0, dtype: object
Альтернатива:
s.str.replace(r'\s+\(([^\)])\)', r'_ID_\1')
Если вы хотитебыть менее явным.
Regex Объяснение
( # matching group 1
\w+ # matches any word character
)
\s+ # matches one or more spaces
\( # matches the character (
( # matching group 2
[^\)] # matches any character that IS NOT )
)
\) # matches the character )