2017-09-15 48 views

回答

4

這應該這樣做:

email['ADDR'] = email['ADDR'].str.replace('.{3}$', 'mn') 

如果您需要處理可變長度域(.edu.com1,等等),你可以使用:

email 

      ADDR 
0 [email protected] 
1 [email protected] 
2 [email protected] 

email['ADDR'].str.replace('\..{2,}$', '.mn') 

0 [email protected] 
1  [email protected] 
2  [email protected] 
Name: ADDR, dtype: object 
+1

只要打開這個問題,有你的好和簡潔的答案〜 – Wen

+1

嘿謝謝你這工作 – RustyShackleford

2

另一種方法,將處理可變長度的頂級結局使用str.rsplit

In[72]: 
df = pd.DataFrame({'email':['[email protected]','[email protected]','[email protected]']}) 
df 

Out[72]: 
       email 
0 [email protected] 
1  [email protected] 
2 [email protected] 

In[73]: 
df['email'] = df['email'].str.rsplit('.').str[0] +'.mn' 
df 

Out[73]: 
      email 
0 [email protected] 
1 [email protected] 
2 [email protected] 

這將找到最後的結尾點,採取左側並追加新的期望後綴

+1

嗯,不錯和簡單。 –

+0

嘿,這工作得很好!非常感謝 – RustyShackleford

相關問題