Count in Python (word frequency)

Source: Internet
Author: User

1, for list lists, a. Using custom functions for statistical techniques
def get_count (Sequence):    counts={}    for in  sequence:        if   in sequence:            +=1        Else:            =1    return counts

Or use the Python standard library

 from Import defaultdict def get_counts (Sequence):         = defaultdict (int)# All values are initialized to 0 forin      sequence:        +=1    return counts
B. Using the Collections.counter class of the Python standard library
 from Import  = Counter (' list name ') counts. Most_common# Top 10-bit count
2, for Dataframe.

For an object series returned by a column in a Dataframe object, such as frame[' property name ', there is a value_counts method,

Counts = frame[' property name '].value_counts ()

Count in Python (word frequency)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.