0
How to combine multiple (many) .txt files into one

Kinda self explanatory. So for a project I'm writing an RNN to generate text, and I was planning to train it with Cornell's database of congressional speeches. The DB is composed of many short text files, but for my purpose, I would like to combine all of these into one very large .txt file, and then convert it to a .csv. Is there an easy way to do this?

Thanks in advance!


Python 04-02-20, 3:33 p.m. tyresebro1
0

I am assuming all the .txt files are in the same folder and distributed in different directories.

I will provide an example to read all the text from the text files https://pastebin.com/TUtQv6xj

The code in the pastebin actually creates an array of all the test from the .txt files. To save it in the CSV you may have to somehow create the labels with which the text should be associated. As you have not provided sufficient information regarding the labels in CSV, I may not be able to help you much on that.

05-02-20, 3:26 p.m. iakashchavan


Log-in to answer to this question.