Python Forum

Full Version: [split] How to convert the CSV text file into a txt file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
(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.
(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.
Do you want a file for each row? Otherwise I don't understand what you mean, because again, CSV is already text.
(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.
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.