两个思路:
-
在pandas里对dataframe进行统计
>>> import pandas as pd >>> a=pd.DataFrame(data=[[1,2,3,4],[3,5,2,6],[6,2,8,4],[4,1,6,3]]) >>> a 0 1 2 3 0 1 2 3 4 1 3 5 2 6 2 6 2 8 4 3 4 1 6 3 >>> a.stack().value_counts() 6 3 4 3 3 3 2 3 1 2 8 1 5 1 dtype: int64
-
转换成list做统计
>>> import collections >>> a = [1,1,1,1,2,2,2,2,3,3,4,5,5] >>> counter=collections.Counter(a) >>> print counter Counter({1: 4, 2: 4, 3: 2, 5: 2, 4: 1})