how to write add frequency in particular file by reading a csv file and then making a new file of multiple csv file by adding frequency
kishan.sampat.cerelabs at gmail.com
kishan.sampat.cerelabs at gmail.com
Thu Jun 22 07:16:16 EDT 2017
I want to write a common file in which It can add the frequency by adding multiple csv file and if the same words are repeated in python then it should add the frequency in the common file can any one help me please
import re
import operator
import string
class words:
def __init__(self,fh):
self.fh = fh
def read(self):
for line in fh:
yield line.split()
if __name__ == "__main__":
frequency = {}
document_text = open('data_analysis.csv', 'r')
common1_file = open("common_file1.csv", "r")
text_string = document_text.read().lower()
match_pattern = re.findall(r'\b[a-z]{3,15}\b', text_string)
text_string_one = common1_file.read().lower()
match_pattern_one = re.findall(r'\b[a-z]{3,15}\b', text_string_one)
#print("match_pattern"+(str(match_pattern)))
for word in match_pattern:
for word1 in match_pattern_one:
count = frequency.get(word,0)
count1 = frequency.get(word1,0)
if word1 == word:
frequency[word] = count + count1
else:
frequency[word] = count
frequency_list = frequency.keys()
text_file = open("common_file1.csv", "w")
for words in frequency_list:
data = (words, frequency[words])
print (data)
#text_file = open("common_file1.csv", "w")
#for i in data:
#store_fre = (str(data)+"\n")
text_file.write(str(data)+"\n")
text_file.close()
this is my code written by me til now but not getting satisfied results
More information about the Python-list
mailing list