With pandas 0.19.2 python 3.6.0 DataFrame.replace with a dictionary acts on substrings (like "find"), and so does Series.replace. Pandas 0.24.0 python 3.6.8 seems to act on the entire string (like "match") for DataFrames, and still act on substrings for Series (like "find").
df = pd.DataFrame({'c1':['AD','BD'],'c2':['AD','BD']})
print(df)
print(df.replace(to_replace={'c1':{r'D': ''}, 'c2':{r'BD': ''}},regex=True))
print(df.replace(to_replace={r'D': ''},regex=True))
print(df['c1'].replace(to_replace=r'D', value='',regex=True))
Pandas 0.19.2 produces (I added some blank lines for legibility):
c1 c2
0 AD AD
1 BD BD
c1 c2
0 A AD
1 B
c1 c2
0 A A
1 B B
0 A
1 B
Name: c1, dtype: object
With Pandas 0.24.0:
c1 c2
0 AD AD
1 BD BD
c1 c2
0 AD AD
1 BD
c1 c2
0 AD AD
1 BD BD
0 A
1 B
Name: c1, dtype: object
Looks like a pandas bug to me, or am I missing something?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…