Tunnels.collect_codes_by_page¶
- Tunnels.collect_codes_by_page(page_no, update=False, verbose=False)[source]¶
Collects data of railway tunnel lengths for a specified page number from the source web page.
- Parameters:
page_no (int | str) – The page number to collect data from; valid values are
1
,2
,3
and4
.update (bool) – Whether to check for updates to the package data; defaults to
False
.verbose (bool | int) – Whether to print relevant information to the console; defaults to
False
.
- Returns:
A dictionary containing the data of tunnel lengths for the specified
page_no
and the date of when the data was last updated.- Return type:
dict
Examples:
>>> from pyrcs.other_assets import Tunnels # from pyrcs import Tunnels >>> tunl = Tunnels() >>> page_1 = tunl.collect_codes_by_page(page_no=1) >>> type(page_1) dict >>> list(page_1.keys()) ['Page 1 (A-F)', 'Last updated date'] >>> page_1_codes = page_1['Page 1 (A-F)'] >>> type(page_1_codes) pandas.core.frame.DataFrame >>> page_1_codes.head() Name Other names, remarks ... Length (metres) Length (note) 0 Abbotscliffe ... 1775.7648 1 Abercanaid see Merthyr ... NaN Unavailable 2 Aberchalder see Loch Oich ... NaN Unavailable 3 Aberdovey No 1 also called Frongoch ... 182.8800 4 Aberdovey No 2 also called Morfor ... 200.2536 [5 rows x 10 columns] >>> page_4 = tunl.collect_codes_by_page(page_no=4) >>> type(page_4) dict >>> list(page_4.keys()) ['Page 4 (others)', 'Last updated date'] >>> page_4_codes = page_4['Page 4 (others)'] >>> type(page_4_codes) dict >>> list(page_4_codes.keys()) ['Tunnels on industrial and other minor lines', 'Large bridges that are not officially tunnels but could appear to be so'] >>> key1 = 'Tunnels on industrial and other minor lines' >>> page_4_dat = page_4_codes[key1] >>> type(page_4_dat) pandas.core.frame.DataFrame >>> page_4_dat.head() Name Other names, remarks ... Length (metres) Length (note) 0 Ashes Quarry ... 56.6928 1 Ashey Down Quarry ... 33.8328 2 Baileycroft Quarry No 1 ... 28.3464 3 Baileycroft Quarry No 2 ... 21.0312 4 Basfords Hill ... 46.6344 [5 rows x 6 columns] >>> key2 = 'Large bridges that are not officially tunnels but could appear to be so' >>> page_4_dat_ = page_4_codes[key2] >>> type(page_4_dat_) pandas.core.frame.DataFrame >>> page_4_dat_.head() Name Other names, remarks ... Length (metres) Length (note) 0 A470/A472 (north) ... 35.6616 1 A470/A472 (south) ... 28.3464 2 A720 ... 145.3896 3 A9 Aberdeen line ... 141.7320 4 A9 Perth line ... 146.3040 [5 rows x 8 columns]