LocationIdentifiers.make_loc_id_dict¶
-
LocationIdentifiers.
make_loc_id_dict
(keys, initials=None, drop_duplicates=False, as_dict=False, main_key=None, save_it=False, data_dir=None, update=False, verbose=False)[source]¶ Make a dict/dataframe for location code data for the given
keys
.- Parameters
keys (str, list) – one or a sublist of [‘CRS’, ‘NLC’, ‘TIPLOC’, ‘STANOX’, ‘STANME’]
initials (str, list, None) – one or a sequence of initials for which the location codes are used, defaults to
None
drop_duplicates (bool) – whether to drop duplicates, defaults to
False
as_dict (bool) – whether to return a dictionary, defaults to
False
main_key (str or None) – key of the returned dictionary if
as_dict
isTrue
, defaults toNone
save_it (bool) – whether to save the location codes dictionary, defaults to
False
data_dir (str or None) – name of package data folder, defaults to
None
update (bool) – whether to check on update and proceed to update the package data, defaults to
False
verbose (bool or int) – whether to print relevant information in console as the function runs, defaults to
False
- Returns
dictionary or a data frame for location code data for the given
keys
- Return type
dict, pandas.DataFrame, None
Examples:
>>> from pyrcs.line_data import LocationIdentifiers >>> lid = LocationIdentifiers() >>> key = 'STANOX' >>> stanox_dictionary = lid.make_loc_id_dict(key) >>> print(stanox_dictionary.head()) Location STANOX 00005 Aachen 04309 Abbeyhill Junction 04311 Abbeyhill Signal E811 04308 Abbeyhill Turnback Sidings 88601 Abbey Wood >>> keys_ = ['STANOX', 'TIPLOC'] >>> initial_ = 'a' >>> stanox_dictionary = lid.make_loc_id_dict(keys_, initial_) >>> print(stanox_dictionary.head()) Location STANOX TIPLOC 00005 AACHEN Aachen 04309 ABHLJN Abbeyhill Junction 04311 ABHL811 Abbeyhill Signal E811 04308 ABHLTB Abbeyhill Turnback Sidings 88601 ABWD Abbey Wood >>> keys_ = ['STANOX', 'TIPLOC'] >>> initial_ = 'b' >>> stanox_dictionary = lid.make_loc_id_dict( ... keys_, initial_, as_dict=True, main_key='Data') >>> type(stanox_dictionary) <class 'dict'> >>> print(list(stanox_dictionary['Data'].keys())[:5]) [('55115', ''), ('23490', 'BABWTHL'), ('38306', 'BACHE'), ('66021', 'BADESCL'), ('81003', 'BADMTN')]