Get stops within an area
Instead of looking at the dataset for all of England, Scotland and Wales, we might just be interested in stops within an area. Using the ATCO area codes we can limit the API request to a specific set of stops — meaning less post-filtering and a faster response time.
For example, to get just the stops of Leicestershire we can pass its area code
of '260' into the naptan.get_area_stops
function.
Info
This function requires a list be passed into the area_codes
parameter. Even just for a single area.
The code can be passed in as a number or a string.
import naptan
# pass in the area code for Leicestershire
naptan.get_area_stops(['260']) # passed in as a list
ATCOCode | NaptanCode | PlateCode | CleardownCode | CommonName | CommonNameLang | ShortCommonName | ShortCommonNameLang | Landmark | LandmarkLang | ... | TimingStatus | DefaultWaitTime | Notes | NotesLang | AdministrativeAreaCode | CreationDateTime | ModificationDateTime | RevisionNumber | Modification | Status | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 260000001 | leidmpwd | NaN | NaN | Parish Hall | NaN | NaN | NaN | Parish Hall | NaN | ... | OTH | NaN | NaN | NaN | 88 | 2002-12-10T00:00:00.000 | 2013-05-10T10:22:22.000 | 5 | revise | active |
1 | 260000002 | leidmpwg | NaN | NaN | Parish Hall | NaN | NaN | NaN | Parish Hall | NaN | ... | OTH | NaN | NaN | NaN | 88 | 2002-12-10T00:00:00.000 | 2013-05-10T10:23:01.000 | 4 | revise | active |
2 | 260000003 | leidmpwj | NaN | NaN | Jubilee Avenue | NaN | NaN | NaN | 48 Main Street | NaN | ... | OTH | NaN | NaN | NaN | 88 | 2002-12-10T00:00:00.000 | 2018-11-15T17:05:40.716 | 8 | revise | active |
3 | 260000004 | leidmpwm | NaN | NaN | Cross Lane | NaN | NaN | NaN | Cross Lane | NaN | ... | OTH | NaN | NaN | NaN | 88 | 2002-12-10T00:00:00.000 | 2011-11-07T15:50:10.000 | 10 | revise | active |
4 | 260000005 | leidmpwp | NaN | NaN | All Saints Close | NaN | NaN | NaN | The Horse Shoes PH | NaN | ... | OTH | NaN | NaN | NaN | 88 | 2002-12-10T00:00:00.000 | 2014-01-03T10:28:52.000 | 7 | revise | active |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
4312 | 260014121 | leimjdjg | NaN | NaN | Methodist Church | NaN | NaN | NaN | NaN | NaN | ... | TIP | NaN | NaN | NaN | 88 | 2022-05-13T14:06:48.584 | 2022-06-29T15:18:19.469 | 1 | revise | active |
4313 | 260026320 | leimjgmw | NaN | NaN | Windsor Close | NaN | NaN | NaN | NaN | NaN | ... | TIP | NaN | NaN | NaN | 88 | 2022-08-24T15:58:19.598 | 2022-08-24T15:58:19.598 | 0 | new | active |
4314 | 260015913 | leimwtpj | NaN | NaN | The Moor | NaN | NaN | NaN | NaN | NaN | ... | TIP | NaN | NaN | NaN | 88 | 2022-09-12T20:09:09.584 | 2022-09-12T20:09:09.584 | 0 | new | active |
4315 | 260014423 | leimtpgj | NaN | NaN | Frederick Avenue | NaN | NaN | NaN | NaN | NaN | ... | TIP | NaN | NaN | NaN | 88 | 2022-09-30T09:53:54.141 | 2022-09-30T17:10:48.556 | 2 | revise | inactive |
4316 | 260014252 | leimjgjg | NaN | NaN | Oak Drive | NaN | NaN | NaN | NaN | NaN | ... | TIP | NaN | NaN | NaN | 88 | 2022-12-05T13:43:24.479 | 2022-12-05T13:43:24.479 | 0 | new | active |
4317 rows × 43 columns
We can ask for an arbitrary number of areas at once. For example, we can get both Leicester and Leicestershire by passing in their respective area codes (269, 260).
import naptan
naptan.get_area_stops([269, 260])
ATCOCode | NaptanCode | PlateCode | CleardownCode | CommonName | CommonNameLang | ShortCommonName | ShortCommonNameLang | Landmark | LandmarkLang | ... | TimingStatus | DefaultWaitTime | Notes | NotesLang | AdministrativeAreaCode | CreationDateTime | ModificationDateTime | RevisionNumber | Modification | Status | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 260000001 | leidmpwd | NaN | NaN | Parish Hall | NaN | NaN | NaN | Parish Hall | NaN | ... | OTH | NaN | NaN | NaN | 88 | 2002-12-10T00:00:00.000 | 2013-05-10T10:22:22.000 | 5 | revise | active |
1 | 260000002 | leidmpwg | NaN | NaN | Parish Hall | NaN | NaN | NaN | Parish Hall | NaN | ... | OTH | NaN | NaN | NaN | 88 | 2002-12-10T00:00:00.000 | 2013-05-10T10:23:01.000 | 4 | revise | active |
2 | 260000003 | leidmpwj | NaN | NaN | Jubilee Avenue | NaN | NaN | NaN | 48 Main Street | NaN | ... | OTH | NaN | NaN | NaN | 88 | 2002-12-10T00:00:00.000 | 2018-11-15T17:05:40.716 | 8 | revise | active |
3 | 260000004 | leidmpwm | NaN | NaN | Cross Lane | NaN | NaN | NaN | Cross Lane | NaN | ... | OTH | NaN | NaN | NaN | 88 | 2002-12-10T00:00:00.000 | 2011-11-07T15:50:10.000 | 10 | revise | active |
4 | 260000005 | leidmpwp | NaN | NaN | All Saints Close | NaN | NaN | NaN | The Horse Shoes PH | NaN | ... | OTH | NaN | NaN | NaN | 88 | 2002-12-10T00:00:00.000 | 2014-01-03T10:28:52.000 | 7 | revise | active |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
5980 | 2690ZZGCLCN | lecdptpd | NaN | NaN | Great Central Railway | NaN | NaN | NaN | Railway Station | NaN | ... | NaN | NaN | NaN | NaN | 27 | 2009-12-11T00:00:00.000 | 2011-08-02T15:16:01.000 | 2 | revise | inactive |
5981 | 2690ZZGCLCN0 | NaN | NaN | NaN | Great Central Railway | NaN | NaN | NaN | Railway Station | NaN | ... | NaN | NaN | NaN | NaN | 27 | 2011-08-02T10:39:25.000 | 2012-04-02T13:33:42.000 | 1 | revise | active |
5982 | 269030128 | lecdptwj | NaN | NaN | Gravel Street | NaN | NaN | NaN | NaN | NaN | ... | TIP | NaN | NaN | NaN | 27 | 2020-10-01T17:38:12.558 | 2021-01-06T11:18:30.471 | 4 | revise | active |
5983 | 269030094 | lecdptwp | NaN | NaN | St Margaret's Bus Station | NaN | NaN | NaN | NaN | NaN | ... | TIP | NaN | NaN | NaN | 27 | 2022-03-28T17:12:24.210 | 2022-03-28T17:12:24.210 | 0 | new | active |
5984 | 269030095 | lecdtgpj | NaN | NaN | St Margaret's Bus Station | NaN | NaN | NaN | NaN | NaN | ... | TIP | NaN | NaN | NaN | 27 | 2022-03-28T17:18:11.791 | 2022-03-28T17:18:11.791 | 0 | new | active |
5985 rows × 43 columns
If we want to do larger areas we can let the naptan.ATCO_CODES
table do some of
the heavy lifting. For example, to get the stops for all of the East Midlands
region we can query the lookup table for the "EM" region, and pass this to the
function.
import naptan
east_mids_codes = naptan.ATCO_CODES.query('Region == "EM"')['Code']
naptan.get_area_stops(east_mids_codes)
ATCOCode | NaptanCode | PlateCode | CleardownCode | CommonName | CommonNameLang | ShortCommonName | ShortCommonNameLang | Landmark | LandmarkLang | ... | TimingStatus | DefaultWaitTime | Notes | NotesLang | AdministrativeAreaCode | CreationDateTime | ModificationDateTime | RevisionNumber | Modification | Status | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0590PEE442 | PETGAGT | NaN | NaN | Durham Road | NaN | NaN | NaN | Durham Road | NaN | ... | OTH | NaN | NaN | NaN | 41 | 2002-12-09T00:00:00 | 2020-08-19T10:45:32 | 5.0 | revise | active |
1 | 059013714 | PETPTJP | NaN | NaN | Adj Whitby Ave | NaN | NaN | NaN | NaN | NaN | ... | OTH | NaN | NaN | NaN | 41 | 2020-05-14T14:36:52 | 2020-05-14T14:36:52 | 0.0 | new | active |
2 | 0590P312906 | PETPJDT | NaN | NaN | Andrew Close | NaN | NaN | NaN | NaN | NaN | ... | OTH | NaN | NaN | NaN | 41 | 2002-01-21T00:00:00 | 2010-04-26T00:00:00 | 6.0 | revise | inactive |
3 | 0590P312905 | PETPJDP | NaN | NaN | Casworth Way | NaN | NaN | NaN | NaN | NaN | ... | OTH | NaN | NaN | NaN | 41 | 2002-01-21T00:00:00 | 2010-04-26T00:00:00 | 6.0 | revise | inactive |
4 | 0590P312901 | PETPJDA | NaN | NaN | Helpston Road | NaN | NaN | NaN | NaN | NaN | ... | OTH | NaN | NaN | NaN | 41 | 2002-01-21T00:00:00 | 2010-04-26T00:00:00 | 5.0 | revise | inactive |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
39281 | 3390WO84A | ntmwtjgw | WO84A | NaN | Far Rye | NaN | NaN | NaN | NaN | NaN | ... | OTH | NaN | NaN | NaN | 39 | 2021-05-13T15:15:04.516 | 2021-05-13T15:15:04.516 | 0.0 | new | active |
39282 | 3390SA26a | ntmwtjgm | SA26a | NaN | Comyn Gardens | NaN | NaN | NaN | NaN | NaN | ... | OTH | NaN | NaN | NaN | 39 | 2022-06-13T10:38:38.417 | 2022-06-13T10:38:38.417 | 0.0 | new | active |
39283 | 3390SH69a | ntmwtjgp | SH69a | NaN | Archdale Road | NaN | NaN | NaN | NaN | NaN | ... | OTH | NaN | NaN | NaN | 39 | 2022-06-13T10:43:44.340 | 2022-06-13T10:43:44.340 | 0.0 | new | active |
39284 | 3390BU102 | ntmwtjgt | BU102 | NaN | Wingbourne Walk | NaN | NaN | NaN | Ken Martin Leisure Centre | NaN | ... | OTH | NaN | NaN | NaN | 39 | 2022-06-13T10:53:46.548 | 2022-06-13T10:59:30.437 | 1.0 | revise | active |
39285 | 3390BU100A | ntmwtjgj | NaN | NaN | Wingbourne Walk | NaN | NaN | NaN | NaN | NaN | ... | OTH | NaN | NaN | NaN | 39 | 2022-07-13T15:10:38.439 | 2022-07-13T15:16:25.790 | 1.0 | revise | active |
39286 rows × 43 columns