我想替换icashier.alipay.com列中的子字符串df
icashier.alipay.com
df
url icashier.alipay.com/catalog/2758186/detail.aspx icashier.alipay.com/catalog/2758186/detail.aspx icashier.alipay.com/catalog/2758186/detail.aspx vk.com
到aliexpress.com。
aliexpress.com
需求输出
aliexpress.com/catalog/2758186/detail.aspx aliexpress.com/catalog/2758186/detail.aspx aliexpress.com/catalog/2758186/detail.aspx vk.com
我尝试,df['url'].replace('icashier.alipay.com', 'aliexpress.com', 'inplace=True')但它返回empty dataframe。
df['url'].replace('icashier.alipay.com', 'aliexpress.com', 'inplace=True')
empty dataframe
使用replace与dict更换和regex=True:
replace
dict
regex=True
df['url'] = df['url'].replace({'icashier.alipay.com': 'aliexpress.com'}, regex=True) print (df) url 0 aliexpress.com/catalog/2758186/detail.aspx 1 aliexpress.com/catalog/2758186/detail.aspx 2 aliexpress.com/catalog/2758186/detail.aspx 3 vk.com