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
Question [SOLVED] Correct way to convert file from cp-1252 to utf-8? Winfried 8 546 Feb-29-2024, 12:30 AM
Last Post: Winfried
  file open "file not found error" shanoger 8 946 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Replace a text/word in docx file using Python Devan 4 2,859 Oct-17-2023, 06:03 PM
Last Post: Devan
  Need to replace a string with a file (HTML file) tester_V 1 699 Aug-30-2023, 03:42 AM
Last Post: Larz60+
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,054 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  How can I change the uuid name of a file to his original file? MaddoxMB 2 874 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  Convert File to Data URL michaelnicol 3 1,083 Jul-08-2023, 11:35 AM
Last Post: DeaD_EyE
  save values permanently in python (perhaps not in a text file)? flash77 8 1,121 Jul-07-2023, 05:44 PM
Last Post: flash77
  How to "tee" (=split) output to screen and into file? pstein 6 1,292 Jun-24-2023, 08:00 AM
Last Post: Gribouillis
  Python Script to convert Json to CSV file chvsnarayana 8 2,346 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020