Skip to content
Advertisement

pandas pivot_tables doesn’t work with date data (No numeric types to aggregate)

I have the following dataframe:

JavaScript

I want to create pivot table to get the following table:

JavaScript

I have tried to do this using pivot_table (pandas):

JavaScript

but I get this error:

DataError: No numeric types to aggregate

I have read this post but it seems to be a bit different as I don’t want to change the columns and also I got error when I tried to set_index with code and id ( ” ValueError: Index contains duplicate entries, cannot reshape”).

My goal is to create pivot table with dates as values of the table.

Advertisement

Answer

There are duplicates per id, date, data so is necessary add some aggregate function:

If there are datetimes:

JavaScript

If there are strings:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement