Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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            |

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading