我正在阅读这样的csv文件:
label, text
a, 'here's some textnwith a new line'
b, 'and some morenwith a new line'
我目前正在这样阅读它:
df = pd.read_csv(file, quotechar="'", escapechar="\")
数据框是使用文本创建的,其中仅包含n
应该所在的"n"字符。
这里有一些带有新行的文本"还有一些带有新行的 moren">
当我在 csv 中读取数据帧时,如何保留其他转义字符,例如 ?
阅读 CSV 后,您始终可以只替换 \:
df['text'] = df['text'].str.replace(r"\'s", "'s", regex=True)
print(df)
label text
0 a 'here's some textnwith a new line'
1 b 'and some morenwith a new line'