title: Python: Tag keywords and create new columns of tags with 1's and 0's
body: <p>I have the below code to iterate through sentences of a column, tag keywords in sentences, and create new columns of those tags consisting of 1's and 0's. If a keyword exists, it is automatically tagged and given a 1 in a new column named after the tag. If it does not exist but another keyword exists, it is given a 0. If the sentence does not have any keywords whatsoever, the entire row will be removed.</p>
  <p>The code below is somewhat okay but it still misses keywords and it tags and outputs 1's and 0's on partial words and blank cells (rows with no sentences). I'm not sure what is missing? How do I ensure that it does not miss keywords and does not tag partial words and blank sentences?</p>
  <pre><code>pattern = '|'.join(dict_list)
  tags_id = (df['description_summary']
     .str.extractall(f'({pattern})')[0]
     .map(keyword_dict)
     .reset_index(name='col')
     .assign(value=1)
     .pivot_table(index=[df['issue.id'], df['description_summary']], columns='col', values='value', fill_value=0))
  </code></pre>
  <p>Here is basically the data I'm working with in an excel file:</p>
  <pre><code>    issue.id  description_summary
  
  0   753       Long sentence with keywords ball and hot
  1   937       Long sentence with keywords cold, stick, and glove
  2   
  3   598       Long sentence with NO keywords
  4   574       Long sentence with keywords very cold and cold 
  </code></pre>
  <p>Here is the current (wrong) output:</p>
  <pre><code>    issue.id  description_summary                                     Toy     Temperature 
  
  0    753       Long sentence with keywords ball and hot                1       1
  1    937       Long sentence with keywords cold, stick, and glove      1       1
  2                                                                      1       0
  3    598       Long sentence with NO keywords but outputs 1s and 0s    0       1
  4    574       Long sentence with keywords very cold and cold          1       1
  </code></pre>
  <p>Here is the output I want:</p>
  <pre><code>    issue.id  description_summary                                     Toy     Temperature    
  
  0    753       Long sentence with keywords ball and hot                1       1
  1    937       Long sentence with keywords cold, stick, and glove      1       1
  4    574       Long sentence with keywords very cold and cold          0       1
  </code></pre>
  <p>Here is the dictionary of keywords and tags ('keywords': 'tags'):</p>
  <pre><code>dict_list = {'Hot': 'Temperature',
   'Cold': 'Temperature',
   'Very cold': 'Temperature',
   'Ball': 'Toy',
   'Glove': 'Toy',
   'Stick': 'Toy'
   }
  </code></pre>
  <p>How do I ensure that it does not miss keywords and does not tag partial words and blank sentences?</p>