0

Possible Duplicate:
pandas: Frequency table for a single variable

I am looking for a function to count number of different strings in an array (It is in the format of pandas series). I have this loop but need something more efficient.

from pandas import *
ser = Series(['a', 'a', 'b', 'b', 'b', 'c', 'c'])
def occuranceCount(ser):
    labels = []
    x = ''
    for i in range(len(ser)):
        if ser[i] != x:            
            labels.append(ser[i])
            x = ser[i]
    return labels

print len(occuranceCount(ser)) 

The main question is to count how many different labels I've got, but also need to know how many time particular label occur in the array. Thanks

Community
  • 1
  • 1
tomasz74
  • 13,747
  • 10
  • 32
  • 49

0 Answers0