CODE:
#!/usr/bin/python #-*-Coding:utf-8-*-"Created on 2014-8-19@author:guaguastd@name:company_suffix_normalize.py" # import Jsonimport Osimport csvfrom collections Import counterfrom operator import itemgetterfrom prettytable import Pret tytable# Specify CSV directorycsv_file = Os.path.join (r "E:", "\ \", "Eclipse", "LinkedIn", "Dfile", "My_connections.csv") # define a set of transforms that converts the first item# to the second itemtransforms = [(', Inc ', '), (', Inc ', '), (', LLC ', '), (', LLP ', '), (' LLC ', '), (' Inc ', '), (' Inc ', ')]csvreader = csv. Dictreader (Open (csv_file), delimiter= ', ', quotechar= ' "') contacts = [row for row in csvreader]companies = [c[' Company ']. Strip () for C-Contacts if c[' Company '].strip ()! = ']for I, _ in Enumerate (companies): For transform in transforms: Companies[i] = Companies[i].replace (*transform) pt = prettytable (field_names=[' company ', ' Freq ']) pt.align = ' l ' c = C Ounter (companies) [Pt.add_row ([Company, Freq]) for (company, Freq) IN Sorted (C.items (), Key=itemgetter (1), reverse=true) if Freq > 0]print pt
RESULT:
+---------------------------------------+------+| Company | Freq |+---------------------------------------+------+|?????????? | 1 | |?? | 1 | | Softtalent Consulting??????????????? | 1 | | SJTU | 1 | | WatchGuard Technologies | 1 | | Hebei meishen Chemical Group co.,ltd | 1 | | Bloomberg LP | 1 | | Dihao Trading Co.,ltd | 1 | | CET | 1 | | Pica8 | 1 | | Microsoft | 1 |+---------------------------------------+------+