Appending pandas DataFrame with MultiIndex with data containing new labels, but preserving the integer positions of the old MultiIndex
问题 Base scenario For a recommendation service I am training a matrix factorization model (LightFM) on a set of user-item interactions. For the matrix factorization model to yield the best results, I need to map my user and item IDs to a continuous range of integer IDs starting at 0. I'm using a pandas DataFrame in the process, and I have found a MultiIndex to be extremely convenient to create this mapping, like so: ratings = [{'user_id': 1, 'item_id': 1, 'rating': 1.0}, {'user_id': 1, 'item_id':