Python Forum
[split] How to convert the CSV text file into a txt file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: [split] How to convert the CSV text file into a txt file (/thread-31620.html)



[split] How to convert the CSV text file into a txt file - Pinto94 - Dec-23-2020

Hello there.
Does anyone know how to convert the CSV text file into a txt file? Because I have 2000++ instances(number of rows) in my dataset so I wanna convert the text from each instance(rows) into 1 txt file, is it possible to do in a short time?

I was searching here and there but couldn't get how. Please do let me know if anyone knows about the problem I am facing.Advance Thank you


RE: How to export from Python to Excel? - ndc85430 - Dec-23-2020

(Dec-23-2020, 06:32 AM)Pinto94 Wrote: Hello there.
Does anyone know how to convert the CSV text file into a txt file? Because I have 2000++ instances(number of rows) in my dataset so I wanna convert the text from each instance(rows) into 1 txt file

You're going to need to explain in more detail what you have and what you're trying to do. CSV is text, so what exactly do you want to do? If you have the data in memory, can't you just write it to a file? If you're using Pandas, there are likely facilities to write data frames to CSV files. Show the code you have and what you've tried.


RE: How to export from Python to Excel? - Pinto94 - Dec-23-2020

(Dec-23-2020, 06:41 AM)ndc85430 Wrote:
(Dec-23-2020, 06:32 AM)Pinto94 Wrote: Hello there.
Does anyone know how to convert the CSV text file into a txt file? Because I have 2000++ instances(number of rows) in my dataset so I wanna convert the text from each instance(rows) into 1 txt file

You're going to need to explain in more detail what you have and what you're trying to do. CSV is text, so what exactly do you want to do? If you have the data in memory, can't you just write it to a file? If you're using Pandas, there are likely facilities to write data frames to CSV files. Show the code you have and what you've tried.



I have a CSV file with texts in each row and I would like to convert the texts from each row to a txt file. Since the number of rows are a lot, hence it would be difficult to convert them manually. Just wondering if there is a way that I can do this using python.


RE: How to export from Python to Excel? - ndc85430 - Dec-23-2020

Do you want a file for each row? Otherwise I don't understand what you mean, because again, CSV is already text.


RE: How to export from Python to Excel? - Pinto94 - Dec-23-2020

(Dec-23-2020, 07:52 AM)ndc85430 Wrote: Do you want a file for each row? Otherwise I don't understand what you mean, because again, CSV is already text.


Yes, I want a txt file for each row.


RE: How to export from Python to Excel? - ndc85430 - Dec-23-2020

Why write a Python script to do this when there are already good tools? If you're on Unix (Linux or Mac, for example), then split should help here. On Windows, there may be something similar (or at least there's Cygwin, which will give you the Unix tools).

You really don't need to keep quoting posts in their entirety - it just wastes space.