Python Forum
Converting .txt to .csv file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting .txt to .csv file
#16
Thank You! I think what I will do is parse them myself and then go from there. I'm thinking there is a way to pull the files as .csv format. But I won't know for sure until I get back to work Monday. I could set the script up to be more automatic if the files were .csv format, correct?

Thanks again for everyone's help!

Hope everyone is having a Happy Holiday

-Veronica

(Jan-01-2021, 08:39 AM)buran Wrote: 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]
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,182 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  [split] Help- converting file with pyton script eltomassito 6 3,403 Jul-02-2021, 05:29 PM
Last Post: snippsat
  Help- converting file with pyton script grinleon 3 2,581 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