Python Forum
Converting .txt to .csv file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting .txt to .csv file
#13
yes, it's fixed-width file.
If you want to read it with pandas - look at pandas.read_fwf

or just parse it your self (i.e. there is no much use of pandas if you just want to read it and then write to excel, without doing calcutions).
Also note that there is extra header line (the underlines of the header) which you will need to deal with in pandas.

import pandas as pd

df = pd.read_fwf('mytxt.txt')
df.drop(index=0, inplace=True) # drop the underlines
print(df.head())
Output:
Cutfile Name Start Time End Time Total Time Status ... Dry Run.1 Cut Speed Throughput Feed Rate Operator 1 BWW34580401 B 11/2/2020 6:39:37 AM 11/2/2020 6:40:05 AM 0:00:28 2 ... 0.000 0.000 0.000 0.000 Unknown 2 BWW34580401 B 11/2/2020 6:40:20 AM 11/2/2020 7:11:45 AM 0:31:25 3 ... 0.000 394.513 168.167 40.000 Unknown 3 PRECUT.$$$ 11/2/2020 7:21:07 AM 11/2/2020 7:21:22 AM 0:00:15 3 ... 0.000 354.574 173.032 40.000 Unknown 4 LFRF0106 30D A2 11/2/2020 7:32:59 AM 11/2/2020 8:00:49 AM 0:27:50 3 ... 0.000 430.553 200.613 40.000 Unknown 5 LFRF0106 30D A1 11/2/2020 8:19:21 AM 11/2/2020 9:08:27 AM 0:49:06 3 ... 0.000 430.338 200.812 40.000 Unknown [5 rows x 27 columns]
palladium likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Converting .txt to .csv file - by SunWers - Jan-01-2021, 06:29 AM
RE: Converting .txt to .csv file - by palladium - Jan-01-2021, 06:52 AM
RE: Converting .txt to .csv file - by SunWers - Jan-01-2021, 07:31 AM
RE: Converting .txt to .csv file - by palladium - Jan-01-2021, 07:53 AM
RE: Converting .txt to .csv file - by SunWers - Jan-01-2021, 08:04 AM
RE: Converting .txt to .csv file - by buran - Jan-01-2021, 07:27 AM
RE: Converting .txt to .csv file - by SunWers - Jan-01-2021, 07:39 AM
RE: Converting .txt to .csv file - by buran - Jan-01-2021, 07:41 AM
RE: Converting .txt to .csv file - by SunWers - Jan-01-2021, 07:48 AM
RE: Converting .txt to .csv file - by palladium - Jan-01-2021, 07:56 AM
RE: Converting .txt to .csv file - by buran - Jan-01-2021, 07:54 AM
RE: Converting .txt to .csv file - by SunWers - Jan-01-2021, 07:56 AM
RE: Converting .txt to .csv file - by buran - Jan-01-2021, 08:39 AM
RE: Converting .txt to .csv file - by SunWers - Jan-02-2021, 01:22 AM
RE: Converting .txt to .csv file - by stevenroger - Jan-01-2021, 09:55 AM
RE: Converting .txt to .csv file - by buran - Jan-01-2021, 03:04 PM
RE: Converting .txt to .csv file - by buran - Jan-02-2021, 03:24 AM
RE: Converting .txt to .csv file - by Pedroski55 - Jan-02-2021, 05:03 AM
RE: Converting .txt to .csv file - by caleb_cruze - Jan-04-2021, 01:10 PM
RE: Converting .txt to .csv file - by buran - Jan-04-2021, 01:12 PM
RE: Converting .txt to .csv file - by pruthvi666 - Jan-19-2024, 10:36 AM
RE: Converting .txt to .csv file - by Larz60+ - Jan-20-2024, 10:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting a json file to a dataframe with rows and columns eyavuz21 13 5,110 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  [split] Help- converting file with pyton script eltomassito 6 3,391 Jul-02-2021, 05:29 PM
Last Post: snippsat
  Help- converting file with pyton script grinleon 3 2,567 Sep-23-2020, 11:48 AM
Last Post: grinleon

Forum Jump:

User Panel Messages

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