musif.common.sort module

musif.common.sort.sort_columns(data: pandas.DataFrame, sorting_list: list) pandas.DataFrame[source]

Reorders columns of a Dataframe according to a reference list. Uses sort_list.

Parameters
  • data (DataFrame) – DataFrame whose columns needs to be re-ordered according to some criteria

  • sorting_list (list) – List used as reference to sort columns.

musif.common.sort.sort_dataframe(data: pandas.DataFrame, column: str, sorting_lists: Dict[list, str], key_to_sort: str) pandas.DataFrame[source]

Sorts Dataframe’s rows by a column using a list as a reference. :param data: DataFrame to be re-ordered according to some criteria. :type data: DataFrame :param column: Column of the Dataframe used as key. :type column: str :param sorting_lists: Dictionary containing lists used as reference to sort values. :type sorting_lists: Dict[list] :param key_to_sort: Key from sorting_lists that contains the desired list to be used as reference. :type key_to_sort: str

musif.common.sort.sort_dict(dict_to_sort: dict, reference_list: list) dict[source]

Sorts dictionary keys according to a reference li()

Parameters
  • dict_to_sort (dict) – Dictionary that needs to be sorted according to some criteria

  • main_list (list) – List used as reference to sort the first one.

musif.common.sort.sort_list(list_to_sort: List[str], reference_list: List[str]) List[str][source]

Sorts first list based on the second one. Those elements that are not present in the reference list will be placed at the end. Returns the same list re-ordered.

Parameters
  • list_to_sort (list) – List that needs to be sorted according to some criteria

  • reference_list (str) – List used as reference to sort the first one.