我在資料框中有一列,其中包含一些網址例如之前:
| url | anydata |
| -------------------| ------------------ |
| https://google.com | anydata |
| http:/bing.com | anydata |
| https:/yahoo.com | anydata |
我如何將所有http替換為https?例如之后:
| url | anydata |
| -------------------| ------------------ |
| https://google.com | anydata |
| https:/bing.com | anydata |
| https:/yahoo.com | anydata |
uj5u.com熱心網友回復:
使用正則運算式:
df['url'] = df['url'].str.replace(r'^http\b', 'https', regex=True)
輸出:
>>> df
url anydata
0 https://google.com anydata
1 https:/bing.com anydata
2 https:/yahoo.com anydata
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/467796.html
