title: Using Reg Ex to Match Strings in a Data Frame and Replace - python
body: <p>i have data frame that looks like this </p>
  
  <pre><code>    value
  0   A067-M4FL-CAA-020
  1   MRF2-050A-TFC,60 ,R-12,HT
  2   moreinfo
  3   MZF8-050Z-AAB
  4   GoCats
  5   MZA2-0580-TFD,60 ,R-669,LT
  </code></pre>
  
  <p>i want to be able to strip <code>,60 ,R-12,HT</code> using regex and also deletes the <code>moreinfo</code> and <code>GoCats</code> rows from the df. </p>
  
  <p>My expected Results:</p>
  
  <pre><code>     value
  0   A067-M4FL-CAA-020
  1   MRF2-050A-TFC
  2   MZF8-050Z-AAB
  3   MZA2-0580-TFD
  </code></pre>
  
  <p>I first removed the strings</p>
  
  <pre><code>del = ['hello', 'moreinfo']
  for i in del:
     df = df[value!= i]
  </code></pre>
  
  <p>Can somebody suggest a way to use regex to match and delete all case that do match <code>A067-M4FL-CAA-020</code> or <code>MZF8-050Z-AAB</code> pattern so i don't have to create a list for all possible cases?</p>
  
  <p>I was able to strip a single line like this but i want to be able to strip all matching cases in the dataframe</p>
  
  <pre><code>pattern = r',\w+ \,\w+-\w+\,\w+ *'
  line = 'MRF2-050A-TFC,60 ,R-12,HT'
  for i in re.findall(pattern, line):
     line = line.replace(i,'')
  
  &gt;&gt;&gt; MRF2-050A-TFC
  </code></pre>
  
  <p>I tried adjusting my code but it prints out the same output for each row </p>
  
  <pre><code>pattern = r',\w+ \,\w+-\w+\,\w+ *'
  for d in df:
     for i in re.findall(pattern, d):
       d = d.replace(i,'')
  </code></pre>
  
  <p>Any suggestions will be greatly appreciated. Thanks</p>