Hello!
I need to:
1. Prompt user for text file
2.Analyze file and graph (with bar plot)the 25 most frequent words with length greater than 4
3.The x axis needs to show the word. The a axis is the frequency.
I've built the bulk of the program so far, but am having some trouble with narrowing it down to the 25 most frequent words with length 4.
Also, my plot is missing a couple of things.
Thanks for your help!
import matplotlib.pyplot as plot
def bar_plot(x_axis,y_axis):
plot.plot(x_axis,y_axis, marker='o')
plot.xlabel('Words')
plot.ylabel('Frequency')
plot.legend()
plot.grid()
plot.show()
def main():
import string
ofile=open(raw_input("Please enter the name of a text file :"))
s=ofile.read()
word_freq={}
word_list=s.split()
word_list=[s.translate(None, string.punctuation) for s in word_list]
for word in word_list:
count=word_freq.get(word.lower(),0)
word_freq[word.lower()]=count+1
keys=word_freq.keys()
keys.sort()
print "Word ---> Frequency"
for word in keys:
bar_plot(word, keys)
main()