Why doesn't str.replace replace ALL values in selected pandas dataframe column?
You were on the right track. Replace raw string as follows
summary['Labels'] = summary['Labels'].str.replace(r'test\|','', regex=True)
Labels
0 test 1
1 test 2
2 test 4
Try str.extract
:
df['Labels'] = df['Labels'].str.extract(r'\|(.*)', expand=False) \
.combine_first(df['Labels'])
print(df)
# Output
Labels
0 test 1
1 test 2
2 test 3
3 test 4
4 test 5
5 test 6