Skip to content
Advertisement

DataError: No numeric types to aggregate pandas pivot

I have a pandas dataframe like this:

JavaScript

and I need to convert it to a Matrix like they do here: https://github.com/tr1ten/Anime-Recommender-System/blob/main/HybridRecommenderSystem.ipynb Cell 13.

So I did the following:

JavaScript

user_training_csr = csr_matrix(user_training_interaction.values)

But I get this error:

JavaScript

What am I missing?

Advertisement

Answer

The Pandas Documentation states:

While pivot() provides general purpose pivoting with various data types (strings, numerics, etc.), pandas also provides pivot_table() for pivoting with aggregation of numeric data

Make sure the column is numeric. Without seeing how you create trainingtaken I can’t provide more specific guidance. However the following may help:

  1. Make sure you handle “empty” values in that column. The Pandas guide is a very good place to start. Pandas points out that “a column of integers with even one missing values is cast to floating-point dtype”.
  2. If working with a dataframe, the column can be cast to a specific type via your_df.your_col.astype(int) or for your example, pd.trainingtaken.astype(int)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement