LocationIdentifiers.make_xref_dict

LocationIdentifiers.make_xref_dict(keys, initials=None, main_key=None, as_dict=False, drop_duplicates=False, dump_it=False, dump_dir=None, 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 multiple initials for which the codes are used; defaults to None.

  • main_key (str | None) – Key of the returned dictionary (when as_dict=True); defaults to None.

  • as_dict (bool) – Whether to return a dictionary; defaults to False.

  • drop_duplicates (bool) – Whether to drop duplicates; defaults to False.

  • dump_it (bool) – Whether to save the location codes dictionary; defaults to False.

  • dump_dir (str | None) – Pathname of a directory where the data file is dumped; defaults to None.

  • verbose (bool | int) – Whether to print relevant information in console; defaults to False.

Returns:

A dictionary or a dataframe for location code data for the given keys.

Return type:

dict | pandas.DataFrame | None

Examples:

>>> from pyrcs.line_data import LocationIdentifiers
>>> # from pyrcs import LocationIdentifiers
>>> lid = LocationIdentifiers()
>>> stanox_dictionary = lid.make_xref_dict(keys='STANOX')
>>> type(stanox_dictionary)
pandas.core.frame.DataFrame
>>> stanox_dictionary.head()
                          Location
STANOX
00005                       Aachen
04309           Abbeyhill Junction
04311        Abbeyhill Signal E811
04308   Abbeyhill Turnback Sidings
88601                   Abbey Wood
>>> s_t_dictionary = lid.make_xref_dict(keys=['STANOX', 'TIPLOC'], initials='a')
>>> type(s_t_dictionary)
pandas.core.frame.DataFrame
>>> s_t_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
>>> ks = ['STANOX', 'TIPLOC']
>>> ini = 'b'
>>> main_k = 'Data'
>>> s_t_dictionary = lid.make_xref_dict(ks, ini, main_k, as_dict=True)
>>> type(s_t_dictionary)
dict
>>> list(s_t_dictionary.keys())
['Data']
>>> list(s_t_dictionary['Data'].keys())[:5]
[('55115', ''),
 ('23490', 'BABWTHL'),
 ('38306', 'BACHE'),
 ('66021', 'BADESCL'),
 ('81003', 'BADMTN')]