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
#15
As always time is short at hand. What I accomplished:

- found a station list on page https://www.ndbc.noaa.gov/to_station.shtml
- wrote a script to read maximum value from column 'height' (ignoring 9999.0 values)
- wrote simple script to iterate over sample stations and years
- to-do (didn't have time): parse all station names from stations page; catch only HTTPError 404 Page Not Found (currently silences all errors and this is not good)

I used pandas for data parsing:

stations = [21413, 21414,   21415,   21416,   21417,   21418,   21419,   21420]

maximums = []

for station in stations:
  for year in range(2010, 2018):
    try:
      filename = f'https://www.ndbc.noaa.gov/view_text_file.php?filename={station}t{year}.txt.gz&dir=data/historical/dart/'
      df = pd.read_csv(filename, sep='\s+',header=None,skiprows=2, names=['height'],usecols=[7]).query('height != 9999.0').max()[0]
      maximums.append(df)
    except:
      print(f'Missing: station {station}, year: {year}')
      continue
It reported missing following datafiles:

Output:
Missing: station 21413, year: 2016 Missing: station 21417, year: 2010 Missing: station 21417, year: 2011 Missing: station 21417, year: 2012 Missing: station 21417, year: 2013 Missing: station 21417, year: 2014 Missing: station 21417, year: 2015 Missing: station 21417, year: 2016 Missing: station 21417, year: 2017 Missing: station 21420, year: 2010 Missing: station 21420, year: 2011 Missing: station 21420, year: 2012 Missing: station 21420, year: 2013 Missing: station 21420, year: 2014 Missing: station 21420, year: 2015 Missing: station 21420, year: 2016 Missing: station 21420, year: 2017
This code collected data from 47 files (took maybe 20-30 seconds) and maximum value among them was 5876.116.

Is this something you could take advantage of?
Reply


Messages In This Thread
RE: How to automate list separation. NOOB - by perfringo - Sep-23-2019, 02:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Automate the boring stuff, inserting commas in list srikanth 1 2,129 Jul-02-2019, 02:29 PM
Last Post: metulburr
  Automate the boring stuff, inserting commas in list DJ_Qu 3 4,721 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,442 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