Looping through dataframe to extract substrings that match dictionary
<p>I'm trying to loop through a column in a dataframe, and create a new column using substrings from the looped column if it contains a value in a dictionary.  More specifically, if the individual row in the column of addresses contains a state in the dictionary of state names and abbreviations, then append the state abbreviation to a list that will become the new column.</p>

<p>The below code works for full matches, but isn't scanning the rows for substrings:</p>

<pre><code>import pandas as pd

df = pd.DataFrame((['Austin, Texas',
               'Texas',
               'Seattle, Washington',
               ',,, Texas',
               'Olympia, WA']), columns = ['Place'])

states = {'Texas': 'TX',
      'Washington': 'WA'}

place = df['Place']

results = []

for x in place:
    if x in states:
        results.append(x)
    else:
        results.append(None)

df['State'] = results
df
</code></pre>

<p>Thanks!</p>