0

I'm trying to output a matrix with 4 rows (1st row is header) and over 6000 columns. Each column header is a word from different text documents (rows 1-3). I want to export it to excel so I can easily filter the top 10 words with highest frequency. I get no error, but nothing shows up in the excel file. Where am I going wrong?

np.savetxt('file.csv', matrix_TF, delimiter = ',', newline = '\n', encoding='utf8')
6
  • Is the file written ? Commented Nov 28, 2017 at 0:39
  • 1
    " I want to export it to excel so I can easily filter the top 10 words with highest frequency. " you can do that pretty easily using Python too... Commented Nov 28, 2017 at 0:41
  • Have you tried an absolute path like "/tmp/file.csv"? Commented Nov 28, 2017 at 0:44
  • @PauloScardine Would that help? Commented Nov 28, 2017 at 0:45
  • Yeah I couldn't figure out how to do it in python so I figured it would be faster to just export it to excel? Commented Nov 28, 2017 at 0:48

1 Answer 1

3

I see from your response to another suggestion you would prefer doing this in Python. It's very possible. Check out the collections methods linkd here.

The first section, 8.3.1, shows an example of the most common words found in Hamlet

from collections import Counter

cnt = Counter()

l1 = [['a','b','c','d','e','e','e'],['a','a','a','b','c','d','e'],['a','b','c','c','c','d','e']]

x = 0
for n in l1:
    x += 1
    for tf in n:
        cnt[tf] += 1
    print cnt
    cnt = Counter()
Sign up to request clarification or add additional context in comments.

2 Comments

I have no issue getting the top 10 words from the original text. My concern is with this term frequency matrix (matrix_TF). I need to see this matrix in excel because it contains 3 rows (all different text documents).
You have three text documents. I'm guessing from your question you've created a term frequency matrix, which is a list of header information, document1, document2, and document3. You can still try to use collections. Check out the updated code snippet in my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.