Facebook
From Kadir Çallıoğlu, 1 Month ago, written in Python.
Embed
Download Paste or View Raw
Hits: 157
  1. import pandas as pd
  2. import re
  3.  
  4.  
  5. def extract_url(s):
  6.     match = re.search(r'https?://([A-Za-z0-9._]+)', s)
  7.     return match.group(1) if match else None
  8.  
  9.  
  10. df = pd.DataFrame({
  11.     'Stats_Access_Link': [
  12.         'http://xcd32112.smart_meter.com',
  13.         'https://example.com',
  14.         'http://test_website.com',
  15.         'https://another_example.com'
  16.     ]
  17. })
  18.  
  19. df['Stats_Access_Link'] = df['Stats_Access_Link'].apply(extract_url)
  20.  
  21. print(df['Stats_Access_Link'])
  22.