My data sample is:
comment sarc_majority
0 [?, ?] sarc
1 [0] non-sarc
2 [!, !, !] sarc
3 [0] non-sarc
4 [?] sarc
I want to replace the punctuation with a new name. Such as ? = punct1, ! = punct2, ' = punct3. I tried using read from csv file.
replace_df = pd.read_csv('./final/eng-mly-punct.csv', sep=',', quoting=csv.QUOTE_NONE,
names=["punct", "replacer"])
replace_df.head()
punct replacer
0 ? punct1
1 ! punct2
2 ' punct3
Then I stucked at replacing:
for punct, replacer in replace_df.itertuples(index=False,name=None):
df.comment = df.comment.str.replace(r'\b{0}\b'.format(punct),replacer)
The error is: error: nothing to repeat
What have gone wrong? Or is there any possible way to do this? The desired output should be just like:
comment sarc_majority
0 [punct1, punct1] sarc
1 [0] non-sarc
2 [punct2, punct2, punct2] sarc
3 [0] non-sarc
4 [punct1] sarc
Thanks in advance. Cheers.