title: Python remove everything after specific string and loop through all rows in multiple columns in a dataframe
body: <p>I have a file full of URL paths like below spanning across 4 columns in a dataframe that I am trying to clean:</p>
  <pre><code>Path1 = [&quot;https://contentspace.global.xxx.com/teams/Australia/WA/Documents/Forms/AllItems.aspx?\
  RootFolder=%2Fteams%2FAustralia%2FWA%2FDocuments%2FIn%20Scope&amp;FolderCTID\
  =0x012000EDE8B08D50FC3741A5206CD23377AB75&amp;View=%7B287FFF9E%2DD60C%2D4401%2D9ECD%2DC402524F1D4A%7D&quot;]
  </code></pre>
  <p>I want to remove everything after a specific string which I defined it as &quot;string1&quot; and I would like to loop through all 4 columns in the dataframe defined as &quot;df_MasterData&quot;:</p>
  <pre><code>string1 = &quot;&amp;FolderCTID&quot;
  </code></pre>
  <pre><code>import pandas as pd 
  
  df_MasterData = pd.read_excel(FN_MasterData)
  
  cols = ['Column_A', 'Column_B', 'Column_C', 'Column_D']
  
  for i in cols:  
  
      # Objective: Replace &quot;&amp;FolderCTID&quot;, delete all string after
      string1 = &quot;&amp;FolderCTID&quot;
  
      # Method 1
      df_MasterData[i] = df_MasterData[i].str.split(string1).str[0]
      
      # Method 2
      df_MasterData[i] = df_MasterData[i].str.split(string1).str[1].str.strip()
      
      # Method 3
      df_MasterData[i] = df_MasterData[i].str.split(string1)[:-1]
  </code></pre>
  <p>I did search and google and found similar solutions which were used but none of them work.</p>
  <p>Can any guru shed some light on this? Any assistance is appreciated.</p>
  <p>Added below is a few example rows in column A and B for these URLs:</p>
  <pre><code>Column_A = ['https://contentspace.global.xxx.com/teams/Australia/NSW/Documents/Forms/AllItems.aspx?\
  RootFolder=%2Fteams%2FAustralia%2FNSW%2FDocuments%2FIn%20Scope%2FA%20I%20TOPPER%20GROUP&amp;FolderCTID=\
  0x01200016BC4CE0C21A6645950C100F37A60ABD&amp;View=%7B64F44840%2D04FE%2D4341%2D9FAC%2D902BB54E7F10%7D',\
  'https://contentspace.global.xxx.com/teams/Australia/Victoria/Documents/Forms/AllItems.aspx?RootFolder\
  =%2Fteams%2FAustralia%2FVictoria%2FDocuments%2FIn%20Scope&amp;FolderCTID=0x0120006984C27BA03D394D9E2E95FB\
  893593F9&amp;View=%7B3276A351%2D18C1%2D4D32%2DADFF%2D54158B504FCC%7D']
  
  Column_B = ['https://contentspace.global.xxx.com/teams/Australia/WA/Documents/Forms/AllItems.aspx?\
  RootFolder=%2Fteams%2FAustralia%2FWA%2FDocuments%2FIn%20Scope&amp;FolderCTID=0x012000EDE8B08D50FC3741A5\
  206CD23377AB75&amp;View=%7B287FFF9E%2DD60C%2D4401%2D9ECD%2DC402524F1D4A%7D',\
  'https://contentspace.global.xxx.com/teams/Australia/QLD/Documents/Forms/AllItems.aspx?RootFolder=%\
  2Fteams%2FAustralia%2FQLD%2FDocuments%2FIn%20Scope%2FAACO%20GROUP&amp;FolderCTID=0x012000E689A6C1960E8\
  648A90E6EC3BD899B1A&amp;View=%7B6176AC45%2DC34C%2D4F7C%2D9027%2DDAEAD1391BFC%7D']
  </code></pre>