fetch_loc_names_repl_dict

pyrcs.utils.fetch_loc_names_repl_dict(k=None, regex=False, as_dataframe=False)[source]

Create a dictionary for rectifying location names.

Parameters
  • k (str or int or float or bool or None) – key of the created dictionary, defaults to None

  • regex (bool) – whether to create a dictionary for replacement based on regular expressions, defaults to False

  • as_dataframe (bool) – whether to return the created dictionary as a pandas.DataFrame, defaults to False

Returns

dictionary for rectifying location names

Return type

dict or pandas.DataFrame

Examples:

>>> from pyrcs.utils import fetch_loc_names_repl_dict

>>> repl_dict = fetch_loc_names_repl_dict()
>>> type(repl_dict)
<class 'dict'>
>>> print(list(repl_dict.keys())[:5])
['"Tyndrum Upper" (Upper Tyndrum)',
 'AISH EMERGENCY CROSSOVER',
 'ATLBRJN',
 'Aberdeen Craiginches',
 'Aberdeen Craiginches T.C.']

>>> repl_dict = fetch_loc_names_repl_dict(regex=True, as_dataframe=True)
>>> type(repl_dict)
<class 'pandas.core.frame.DataFrame'>
>>> print(repl_dict.head())
                                 new_value
re.compile(' \(DC lines\)')   [DC lines]
re.compile(' And | \+ ')               &
re.compile('-By-')                    -by-
re.compile('-In-')                    -in-
re.compile('-En-Le-')              -en-le-