0
I’m new to data science and I’m trying to use the Dataframe.pivot() of the Pandas to create a heatmap but he’s returning me this mistake:
Valueerror: Index contains Duplicate Entries, cannot reshape
I’m not able to solve it, but when I change the parameters of pivot()
works, however, many values return as NaN
.
I researched some topics about it but could not find a solution.
The heatmap format will be with the year columns and the rows will be the months.
Structure of the Dataframe
data usuarios ano mes dia ano-mes mes-dia
2018-01-01 215 2018 01 01 2018-01 01-01
2018-01-02 167 2018 01 02 2018-01 01-02
2018-01-03 123 2018 01 03 2018-01 01-03
2018-01-04 193 2018 01 04 2018-01 01-04
2018-01-05 235 2018 01 05 2018-01 01-05
2018-01-06 241 2018 01 06 2018-01 01-06
Series Type
data datetime64[ns]
usuarios int64
ano object
mes object
dia object
ano-mes object
mes-dia object
Attempts
# Com esse trecho, está me retornando o erro que especifiquei acima
test = df.pivot("ano", "mes", "usuarios")
# Utilizando assim ele até funciona, mas todos os valores ficam NaN
test2 = df.pivot("data", "mes", "usuarios")
Values after using the pivot df.pivot("data", "mes", "usuarios")
that worked
mes 01 02 03 04 05 06 07 08 09 10 11 12
data
2018-01-01 215.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2018-01-02 169.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Why values are being set as NaN
and how I could use the pivot
referring only the year and month without returning the mentioned error?
Could you add more lines to the bank so we can replicate the error? If you cannot provide this data, give a minimum replicable example. See instructions here: https://answall.com/help/minimal-reproducible-example
– Lucas
What is your cross-service unit?
– Lucas
if possible, try to clarify what output you want. Your heatmap will have variables in the row and columns?
– Lucas
I edited the question with the information you requested
– Victor Hugo