from collections import Counter
c = Counter('gallahad')
c
Out[17]: Counter({'g': 1, 'a': 3, 'l': 2, 'h': 1, 'd':1})
dict(c)
Out[18]: {'g': 1, 'a': 3, 'l': 2, 'h': 1, 'd': 1}
处理重复列
b = ['age','sex','occupation','age']
c = dict(Counter(b))
c
Out[21]: {'age': 2, 'sex': 1, 'occupation': 1}
h_c = [k for k, value in c.items() if value>1] # 选出重复列'age'
h_c
Out[24]: ['age']