Python Forum
Counting number of words and organize for the bigger frequencies to the small ones.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Counting number of words and organize for the bigger frequencies to the small ones.
#1
Hi, everybody
I am doing a systematic literature review and I copied all the references used in my sample. I would like to identify the most common words in order to identify the authors most citted. I did this so far:
import sys


print(sys.argv[1])

f = open(sys.argv[1])
my_file_contents = f.read()

#print(f.read())

def word_count(str):
    counts = dict()
    words = str.split()

    for word in words:
        if word in counts:
            counts[word] += 1
        else:
            counts[word] = 1

    return counts

print(word_count(my_file_contents))
I was able to identify every word's number, but I do not know how to present from the terms with the most frequent to the fewer ones. Can somebody help me?
nilamo write Feb-05-2021, 08:30 PM:
Please use python tags in the future
Reply
#2
For counting Python has Counter which has convenient most_common and other stuff useful while conducting counting.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 313 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
Star Split and organize my Pandas Dataframe brunolelli 4 720 Apr-18-2021, 03:00 AM
Last Post: brunolelli
  Counting Number of Element in a smart way quest 2 559 Nov-09-2020, 10:24 PM
Last Post: quest
  Find frequencies of an audio file at a specific time via librosa jberesford123__ 0 552 Oct-21-2020, 01:18 PM
Last Post: jberesford123__
  Counting the most relevant words in a text file caiomartins 2 752 Sep-21-2020, 08:39 AM
Last Post: caiomartins
  Best way(s) to organize and use "global" values? pjfarley3 6 1,004 Sep-03-2020, 12:27 AM
Last Post: pjfarley3
  get method not counting number of strings in dictionary LearningTocode 2 672 Jun-13-2020, 11:17 PM
Last Post: LearningTocode
  Convert Int Value bigger 256 to Unicode lastyle 4 1,028 Mar-19-2020, 11:48 AM
Last Post: lastyle
  counting items in a list of number combinations Dixon 2 842 Feb-19-2020, 07:06 PM
Last Post: Dixon
  Counting number of occurrences of a single digit in a list python_newbie09 12 2,329 Aug-12-2019, 01:31 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020