'Replace http from url to https in pandas dataframe

i have a column in dataframe, which contains a few urls For Example before:

| url                | anydata            |
| -------------------| ------------------ |
| https://google.com | anydata            |
| http:/bing.com     | anydata            |
| https:/yahoo.com   | anydata            |

how i can replace all http to https? For example after:


| url                | anydata            |
| -------------------| ------------------ |
| https://google.com | anydata            | 
| https:/bing.com    | anydata            |
| https:/yahoo.com   | anydata            |


Solution 1:[1]

Use a regular expression:

df['url'] = df['url'].str.replace(r'^http\b', 'https', regex=True)

Output:

>>> df
                  url  anydata
0  https://google.com  anydata
1     https:/bing.com  anydata
2    https:/yahoo.com  anydata

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 richardec