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
  [split] Change Text Size in Console? CodingKid 1 91 Jul-20-2021, 02:47 PM
Last Post: deanhystad
  How to convert binary data into text? ZYSIA 3 273 Jul-16-2021, 04:18 PM
Last Post: deanhystad
  [split] Help- converting file with pyton script eltomassito 6 393 Jul-02-2021, 05:29 PM
Last Post: snippsat
  Read file, reformat and write new file bryanmartin113 1 329 Jun-08-2021, 09:27 PM
Last Post: Larz60+
  How to save modification of a file in original file not a new one? mjrezayani 3 542 Jun-04-2021, 01:28 PM
Last Post: snippsat
  Extract specific sentences from text file Bubly 3 343 May-31-2021, 06:55 PM
Last Post: Larz60+
  Filter Excel and Convert an Excel File giddyhead 0 392 May-13-2021, 06:31 PM
Last Post: giddyhead
  Subprocess.Popen() not working when reading file path from csv file herwin 13 1,082 May-07-2021, 03:26 PM
Last Post: herwin
  code for CSV file to html file without pandas jony057 1 449 Apr-24-2021, 09:41 PM
Last Post: snippsat
  Copy column from one existing excel file to another file mkujawsk 0 468 Apr-14-2021, 06:33 PM
Last Post: mkujawsk

Forum Jump:

User Panel Messages

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