Getting a list of suffixes from the company names
<p>I have a data frame df with a column name - Company. Few examples of the company names are: ABC Inc., XYZ Gmbh, PQR Ltd, JKL Limited etc. I want a list of all the suffixes (Inc.,Gmbh, Ltd., Limited etc). Please notice that suffix length is always different. There might be companies without any suffix, for example: Apple. I need a complete list of all suffixes from the all the company names, keeping only unique suffixes in the list.</p>

<p>How do I accomplish this task? </p>

<p>You can use <a href="https://github.com/psolin/cleanco" rel="nofollow">cleanco</a> Python library for that, it has a <a href="https://github.com/psolin/cleanco/blob/master/termdata.py" rel="nofollow">list</a> of all possible suffixes inside. E.g. it contains all the examples you provided (Inc, Gmbh, Ltd, Limited). </p>

<p>So you can take the suffixes from the library and use them as a dictionary to search in your data, e.g.:</p>

<pre><code>import pandas as pd
company_names = pd.Series(["Apple", "ABS LLC", "Animusoft Corp", "A GMBH"])
suffixes = ["llc", "corp", "abc"]  # take from cleanco source code
found = [any(company_names.map(lambda x: x.lower().endswith(' ' + suffix))) for suffix in suffixes]
suffixes_found = [suffix for (suffix, suffix_found) in zip(suffixes, found) if suffix_found]
print suffixes_found  # outputs ['llc', 'corp']
</code></pre>

python pandas