Question: IN PYTHON please help me with programming part and let me know my program isn't working. you can write a pragrom previous exercise: def main():
IN PYTHON please help me with programming part and let me know my program isn't working. you can write a pragrom

previous exercise:
def main(): print("This program analyzes word frequency in a file") print("and prints a report on the n most frequent words. ") # get the sequence of words from the file fname = input("File to analyze: ") text = open(fname,'r').read() text = text.lower() for ch in '!"#$%&()*+,-./:;?@[\\]^_`{|}~': text = text.replace(ch, ' ') words = text.split()
#create a set of stopwords from the stopWordsEng.txt with open("stopWordsEng.txt", "r") as f: stopwords = set(f.read().split()) #count words counts = {} for w in words: if w not in stopwords: counts[w] = counts.get(w,0) + 1
#sorting n = int(input("Output analysis of how many words? ")) items = list(counts.items()) items.sort(key=lambda x: x[1], reverse=True) for i in range(n): print("{}:\t{}".format(items[i][0], items[i][1]))
main()
my program:
def main(): print("This program analyzes word frequency in a file") print("and prints a report on the n most frequent words. ") # get the sequence of words from the file fname = input("File to analyze: ") text = open(fname,'r',encoding="utf-8").read() #uText= text.decode("utf-8") #bText= text.encode("ascii", "ignore") #covert to bytes data type bText= text.encode("utf-8") text= bText.decode("ascii","ignore") print(type(text))
text = text.lower() for ch in '!"#$%&()*+,-./:;?@[\\]^_`{|}~': text = text.replace(ch, ' ') words = text.split()
#count words counts = {} for w in words: counts[w] = counts.get(w,0) + 1 from wordcloud import WordCloud wordcloud = WordCloud(colormap='prism', background_color='white') wordcloud = wordcloud.fit_words(counts) wordcloud = wordcloud.to_file('t.png')
main()
9.1 I (Project: Visualizing Word Frequencies with a Word Cloud) A word cloud visualizes words, displaying more frequently occurring words in larger fonts. In this exercise, you'll create a word cloud that visualizes the top 200 words in Pride and Prejudice. You'll use the open-source wordcloud module's 15 WordCloud class to generate a word cloud with just a few lines of code. To install wordc 1 oud, open your Anaconda Prompt (Windows), Terminal (macOS/ Linux) or shell (Linux) and enter the command: conda insta11 -c conda-forge wordcloud You create and configure a WordCloud object as follows: from wordcloud import WordCloud wordcloud = WordCloud(colormap='prism', background_co1or=' white' ) Using the techniques from the previous exercise, create a frequencies dictionary containing the frequencies of the top-200 words in Pride and Prejudice. Then execute the following statements to generate a rectangular word cloud and save its image to a file on disk: wordcloud = wordcloud.fit_words(frequencies) wordcloud = wordcloud.to_file('PrideAndPrejudice.png') You can then double-click the PrideAndPrejudice.png image file on your system to view it. In the "Natural Language Processing" chapter, we'll show you how to place your word clouds into shapes. For example, we placed our Romeo and Juliet word cloud into a heart
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
