Archive for July, 2010

Python data frequency code

July 9, 2010 5 comments

This is a very simple script which can be used to get the frequency of any dataset. All you need is a list i.e. the data in a python list format.

So if you have a column of data with repetitions and want to know the frequency of occurrence, you want this. It’s very simple but i wrote it and published it help fasten our daily needs 😀
Here is the function.

def create_frequency_dict(a=[]):
value = 0
for i in range(len(a)):
if i==0:
value += 1
elif a[i] == a[i-1]:
value += 1
elif a[i]!=a[i-1]:
s = str(a[i-1])
b[a[i-1]] = value
value = 1
b[a[i]] = value
return b

%d bloggers like this: