0

I have following data,

Unnamed: 5 Week Value
Quartiles Week5 3
CR Week4 2
KPI Week3 1
Quartiles Week5 2
CR Week4 5
KPI Week3 1

I am trying to convert like this

Week Quartiles CR KPI
Week5 3 2 2
Week4 2 5 5
Week3 1 1 4

While running the following code:

df3 = pd.pivot_table(df2,values='value',index='variable',columns='Unnamed: 5',aggfunc='first')

I got following error,

"Index contains duplicate entries, cannot reshape"

I tried different agg function nothing works..

I dont need agg function, I just need to update values as it is...

BeRT2me
  • 12,699
  • 2
  • 13
  • 31
  • Are you sure used `pivot_table` ? Because error `Index contains duplicate entries, cannot reshape` is if use `pivot` – jezrael Nov 14 '22 at 07:15
  • Are data correct for `Week` column in input? From ouput is should be 3 times `Week5` and then 3 times `Week4` – jezrael Nov 14 '22 at 07:19
  • 1
    `pd.pivot_table(df,values='Value',index='Week',columns='Unnamed: 5',aggfunc='first')` Works just fine... what is it you're actually doing? – BeRT2me Nov 14 '22 at 07:20
  • @BeRT2me, index='week' contains multiple duplicate rows, thats why it is throwing error, if I use aggregation function it is shrinking to only 5 rows, but I dont want that. how to skip aggregation and pivot the table as it is? – Krishnamoorthy Nov 14 '22 at 07:51
  • Does this answer your question? [How can I pivot a dataframe?](https://stackoverflow.com/questions/47152691/how-can-i-pivot-a-dataframe) – BeRT2me Nov 14 '22 at 20:38

0 Answers0