I was looking for how to unload the obtained data into a .txt or csv file

Viewed 54

I was looking for how to unload the obtained data into a .txt or csv file, but I could not find a simple and understandable solution with my level of understanding of this process.

I need to sort words by frequency and highlight the top 100 words. I did it (I know not in the best way, I did everything in the Google collaboratori)

from collections import Counter

Counter(" ".join(test_data['body']).split()).most_common(100)

DATA= Counter(" ".join(test_data['body']).split()).most_common(100)

DATA

Question:
how to save the result from these top 100 words to a text file .csv or .txt, and possibly an Excel version.(or in three versions at once)

I'm just learning and don't know a lot, trying to figure it out and understand.

Here is a link to the collab, for me the problem is that the words are Russian, and all the practices are for English texts, and it's easier than working with Russian text. https://colab.research.google.com/drive/1LZ3RHPTjTib8lUjzKGcCJgzYnODSjewL?usp=sharing

1 Answers

As I can see in the colab file you are using pandas so the best way would be to use Pandas to_csv function to write to csv and txt by modifying the delimiter argument

You can write to excel using to_excel

Now since you want the top 100 of a particular column only you can first extract that into a separate dataframe by indexing on the column, sorting it (if not sorted) and using head for range 100

Related