Simple Text Classification in Python
<p>I want to perform a simple text classifcation that performs the following:
- check to see if if each 'loss description' contains a keyword related to a disaster
- if it does, then classify it according to that category; otherwise just show 'Non-Disaster'</p>

<p>Please point out what error I have in the code (the first row in datarecord are just field names) or the more efficient way to write the code:</p>

<pre><code>disaster_cat = [(('lightning'),'lightning'),
                (('hurricane', 'sandy', 'irene', 'isaac', 'gustav'),'Hurricane'),
                (('tornado'),'Tornado'),
                (('flood'),'Flood'),
                (('wildfire', 'wild fire'),'Wild Fire')]

disaster_type = 'Non-Disaster' 
for record in datarecords[1:]:
    record.append(disaster_type) #pre-populate every field with 'Non-Disaster'

for record in datarecords[1:]:    
    for pairs in disaster_cat:        
        for phrase in pairs[0]:            
            if phrase in record[loss_desc_idx]: #check to see if the loss description contains kw
                record[-1] = pairs[1]           #if has kw, change disaster type 'Non-Disaster'
                                                #to appropriate diaster category
</code></pre>

<p>Ideal end result, if loss description is "my car was destroyed by superstorm sandy", the corresponding disaster_type would be "hurricane".</p>
