def transform_item_matrix_to_horizontal_format(folder, output_path='user_item_matrix.pkl', input_path='user_item_matrix_vertical.pq', sortby='ts'):
    '\n    Transforms vertical User-Item matrix where ich row is one click into a horizontal User-item matrix where we have\n    one row for each user and each row contains a (sorted) list of articles she/he clicked on.\n    :param folder: Input folder\n    :param output_path: Filename/path for outputfile\n    :param input_path: Filename/path for inputfile. This pickled file contains a DataFrame with three columns:\n                        "user_ix": the UserID and "article_id" the ArticleID and "<sortby>" which should be timestamp\n                        to sort by. Each UserID ArticleID pair indicates a click of the user on the article at a time.\n    :param sortby: Columnname of the timestamp column to sort by\n    :return: returns a Series where the index is the UserID and values is the by timestamp\n             sorted list of clicked ArticleIDs\n    '
    now = datetime.datetime.now()
    matrices = pd.read_parquet(f'{folder}/{input_path}')
    grouped = matrices.sort_values(sortby).groupby(['user_ix']).apply((lambda x: list(x['article_id'])))
    grouped.to_pickle(f'{folder}/{output_path}')
    print(f'Data transformed {(datetime.datetime.now() - now)}')
Transforms vertical User-Item matrix where ich row is one click into a horizontal User-item matrix where we have
one row for each user and each row contains a (sorted) list of articles she/he clicked on.
:param folder: Input folder
:param output_path: Filename/path for outputfile
:param input_path: Filename/path for inputfile. This pickled file contains a DataFrame with three columns:
                    "user_ix": the UserID and "article_id" the ArticleID and "<sortby>" which should be timestamp
                    to sort by. Each UserID ArticleID pair indicates a click of the user on the article at a time.
:param sortby: Columnname of the timestamp column to sort by
:return: returns a Series where the index is the UserID and values is the by timestamp
         sorted list of clicked ArticleIDs
def transform_item_matrix_to_horizontal_format(folder, output_path='user_item_matrix.pkl', input_path='user_item_matrix_vertical.pq', sortby='ts'):
    '\n    Transforms vertical User-Item matrix where ich row is one click into a horizontal User-item matrix where we have\n    one row for each user and each row contains a (sorted) list of articles she/he clicked on.\n    :param folder: Input folder\n    :param output_path: Filename/path for outputfile\n    :param input_path: Filename/path for inputfile. This pickled file contains a DataFrame with three columns:\n                        "user_ix": the UserID and "article_id" the ArticleID and "<sortby>" which should be timestamp\n                        to sort by. Each UserID ArticleID pair indicates a click of the user on the article at a time.\n    :param sortby: Columnname of the timestamp column to sort by\n    :return: returns a Series where the index is the UserID and values is the by timestamp\n             sorted list of clicked ArticleIDs\n    '
    now = datetime.datetime.now()
    matrices = pd.read_parquet(f'{folder}/{input_path}')
    grouped = matrices.sort_values(sortby).groupby(['user_ix']).apply((lambda x: list(x['article_id'])))
    grouped.to_pickle(f'{folder}/{output_path}')
    print(f'Data transformed {(datetime.datetime.now() - now)}')