Python Forum
[split] How to convert the CSV text file into a txt file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] How to convert the CSV text file into a txt file
#1
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
Reply
#2
(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.
Reply
#3
(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.
Reply
#4
Do you want a file for each row? Otherwise I don't understand what you mean, because again, CSV is already text.
Reply
#5
(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.
Reply
#6
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 6,726 Dec-16-2025, 05:29 PM
Last Post: zodazy
Question [SOLVED] Linefeed when writing "f" strings to text file? Winfried 5 758 Nov-04-2025, 11:51 AM
Last Post: buran
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 13 35,392 May-20-2025, 12:26 PM
Last Post: hanmen9527
  How to write variable in a python file then import it in another python file? tatahuft 4 2,201 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  Problems writing a large text file in python Vilius 4 1,968 Dec-21-2024, 09:20 AM
Last Post: Pedroski55
  Get an FFMpeg pass to subprocess.PIPE to treat list as text file? haihal 2 2,304 Nov-21-2024, 11:48 PM
Last Post: haihal
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 2,208 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 2,656 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 13,947 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  Reading an ASCII text file and parsing data... oradba4u 2 2,801 Jun-08-2024, 12:41 AM
Last Post: oradba4u

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.