Python Forum
How to automate list separation. NOOB
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to automate list separation. NOOB
#8
Look at EDIT in my previous post.

This code should be amended so that two first rows are ignored (where is no data). The could look like:

with open('buoys.txt', 'r') as f:
    rows = (row.strip() for row in f)
    header, header_2 = next(rows), next(rows)
    nums = (float(row.split()[-1]) for row in rows if float(row.split()[-1]) != 9999.0)
    max_value = max(nums)
EDIT:

You can iterate over files and perform same operation, assuming that you have list of files you want to look for max value:

file_list = ['buoys.txt', 'buoys_2.txt']   # long list of filenames. If in one directory you can us os.listdir() to get this list

file_max_values = []

for file in file_list:
    with open(file, 'r') as f:
        rows = (row.strip() for row in f)
        header, header_2 = next(rows), next(rows)
        nums = (float(row.split()[-1]) for row in rows if float(row.split()[-1]) != 9999.0)
        file_max_values.append(max(nums))

max_value = max(file_max_values)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: How to automate list separation. NOOB - by perfringo - Sep-20-2019, 01:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Automate the boring stuff, inserting commas in list srikanth 1 2,130 Jul-02-2019, 02:29 PM
Last Post: metulburr
  Automate the boring stuff, inserting commas in list DJ_Qu 3 4,722 Apr-21-2019, 03:52 PM
Last Post: perfringo
  1. How can I automate this batch creation of documents? 2. How can I automate posting SamLearnsPython 2 3,444 Jul-02-2018, 11:36 AM
Last Post: buran

Forum Jump:

User Panel Messages

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