Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python count the frequency of words in a list

from collections import Counter
list1=['apple','egg','apple','banana','egg','apple']
counts = Counter(list1)

print(counts)
# Counter({'apple': 3, 'egg': 2, 'banana': 1})
Comment

list count frequency python

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})
print(counter.values())
# [4, 4, 2, 1, 2]
print(counter.keys())
# [1, 2, 3, 4, 5]
print(counter.most_common(3))
# [(1, 4), (2, 4), (3, 2)]
Comment

find frequency of numbers in list python

from collections import Counter

def frequency_table(n):
    table = Counter(n)
    print('Number	Frequency')
    for number in table.most_common() :
        print('{0}	{1}'.format(number[0], number[1]))
        
# src : Doing Math With Python
Comment

PREVIOUS NEXT
Code Example
Python :: fill na with mode and mean python 
Python :: convert from epoch to utc python 
Python :: read_csv Unnamed: 0 
Python :: inverse matrice python 
Python :: add header to table in pandas 
Python :: python if not path exist make path 
Python :: get adjacent cells in grid 
Python :: flask console log 
Python :: how to increase size of graph in jupyter 
Python :: python change cwd to script directory 
Python :: write list of dicts to csv python 
Python :: python current utc offset 
Python :: pandas dataframe print decimal places 
Python :: read csv and set column name in pandas 
Python :: pil image base64 
Python :: tkinter gui grid and frame 
Python :: pygame mouse pos 
Python :: how to open csv file in python 
Python :: parameter grid 
Python :: why men are better than woman 
Python :: timer pythongame 
Python :: install python3 6 ubuntu 20 
Python :: car in programming python 
Python :: UnavailableInvalidChannel error in conda 
Python :: add font to the label in window tkinter 
Python :: pd combine date time 
Python :: all subarrays of an array python 
Python :: python install bigquery 
Python :: how to make a window in tkinter 
Python :: pyqt5 qpushbutton disable 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =