Python Forum
[Solved] Using readlines to read data file and sum columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Using readlines to read data file and sum columns
#5
(Jun-16-2021, 12:13 PM)paul18fr Wrote: I'm not a regex expert, but the following code might help you

import re

# line = " 0           2           0      -15000           0"
line = "50           2           2      -14950           3"
Values = re.split(r"\s?([+\-]?\d+)\s+([+\-]?\d+)\s+([+\-]?\d+)\s+([+\-]?\d+)\s+([+\-]?\d+)", line)
print(f"1rst value : {Values[1]}")
print(f"2nd value : {Values[2]}")
print(f"3rd value : {Values[3]}")
print(f"4th value : {Values[4]}")
print(f"5th value : {Values[5]}")

Got the issue resolved by using np.loadtxt and data[-1:1,1] type commands. Thanks for your help!
Reply


Messages In This Thread
RE: Using readlines to read data file and sum columns - by Laplace12 - Jun-16-2021, 12:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 409 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
Question [SOLVED] Correct way to convert file from cp-1252 to utf-8? Winfried 8 853 Feb-29-2024, 12:30 AM
Last Post: Winfried
  Create Choices from .ods file columns cspower 3 604 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,894 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,455 Nov-09-2023, 10:56 AM
Last Post: mg24
  Create csv file with 4 columns for process mining thomaskissas33 3 754 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  read file txt on my pc to telegram bot api Tupa 0 1,127 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,115 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,286 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 6,627 Jun-06-2023, 06:37 PM
Last Post: rajeshgk

Forum Jump:

User Panel Messages

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