Python Forum
Remove Specific Columns when the number of columns is greater than a specific value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove Specific Columns when the number of columns is greater than a specific value
#1
I need to remove 2 columns (column 41 and 42) from a row when the column count within a segment of the row is > 42. I'm extremely new to Python. How would I add it to this section? I want to add if category = 'ABC' and countFields(line) > 42 the remove columns 41 and 42.
ret = []
    for line in file:
        category = line[0:3]
        line = line[4:].strip()
        if category in ('FHS', 'BHS', 'MSH', 'FTS'):
            continue
        elif category == 'PID':
            if _countFields(line) == 18:
                line += "|"
            curPatient = _Patient(line)
            ret.append(curPatient)
        else:
            curPatient.addData(line, category)
    file.close()
    return ret
Larz60+ write Sep-09-2021, 09:23 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  delete specific row of entries jacksfrustration 3 399 Feb-13-2024, 11:13 PM
Last Post: deanhystad
  Converting column of values into muliple columns of counts highland44 0 256 Feb-01-2024, 12:48 AM
Last Post: highland44
  Extracting specific file from an archive tester_V 4 520 Jan-29-2024, 06:41 PM
Last Post: tester_V
  Why can't I copy and past only ONE specific tab? NewWorldRonin 8 806 Jan-12-2024, 06:31 PM
Last Post: deanhystad
  data validation with specific regular expression shaheen07 0 341 Jan-12-2024, 07:56 AM
Last Post: shaheen07
  Create Choices from .ods file columns cspower 3 605 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  Remove some columns James_S 4 810 Dec-16-2023, 11:02 PM
Last Post: James_S
  How to create a table with different sizes of columns in MS word pepe 8 1,575 Dec-08-2023, 07:31 PM
Last Post: Pedroski55
  Create csv file with 4 columns for process mining thomaskissas33 3 757 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  Find a specific keyword after another keyword and change the output sgtmcc 5 826 Oct-05-2023, 07:41 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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