title: Pandas - Extracting based on key words
body: <p>I am trying to extract part of the text from a row using the below condition:</p>
  
  <pre><code>df['output'] = df['subject'].str.split('Class : ').str[1]
  </code></pre>
  
  <p>The above code works well, however if the row has multiple values of <code>Class</code> how could I modify this to extract the last one.</p>
  
  <p>Example:</p>
  
  <pre><code>subject, output
  Class Name : Science, Science
  Class : Class Assigned Class : Math, Class Assigned Class : Math
  </code></pre>
  
  <p>How could I change the code to fix the output for the second row where the expected output is <code>Math</code> but since the word <code>Class</code> appears more than once it fetches from the first occurrence.</p>