您需要通过\ 转义$,因为它被读取为正则表达式(字符串结尾):
(分隔符 > 1 个字符且不同于 '\s+' 被解释为正则表达式)
import pandas as pd
from pandas.compat import StringIO
temp=u"""<first>$$><$$<second>$$><$$<first>$$>
<foo>$$><$$<bar>$$><$$<baz>$$>"""
#after testing replace 'StringIO(temp)' to 'filename.csv'
df = pd.read_csv(StringIO(temp),
encoding='utf8',
sep='\$\$><\$\$',
decimal=',',
header=None,
engine='python')
print (df)
0 1 2
0 <first> <second> <first>$$>
1 <foo> <bar> <baz>$$>
然后对于从最后一列删除$$> 是可能的使用replace(添加& 作为字符串结尾):
df.iloc[:, -1] = df.iloc[:, -1].str.replace('\$\$>$', '')
print (df)
0 1 2
0 <first> <second> <first>
1 <foo> <bar> <baz>
对于删除引用:
df = df.replace(['^<', '>$'], ['', ''], regex=True)
print (df)
0 1 2
0 first second first
1 foo bar baz
两者一起替换:
df = df.replace(['^<', '>$', '>\$\$'], ['', '', ''], regex=True)
print (df)
0 1 2
0 first second first
1 foo bar baz