cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pg-gopinathan
Frequent Visitor

Pivot table using Python facing issue - Index variables are not visible

I tried to pivot a table with aggregate function sum in python. After running python script in power bi I am not able to see index columns which i used to group by. But if I am trying to execute this code in python it's working perfectly by displaying index columns.

 

Here below my code;

 

import pandas as pd

pivotset = dataset.pivot_table(index=['movieID','user'], values=['Rating'], aggfunc='sum')

print(pivotset)

 

         Result in Python is:

 

movieID user             Rating
1             Ali                5
               Ganesh         5
              Jayaram         2
              Kevin             1
              Mithun          3
              Musthafa       3
              Shafi              4
2            Jack               5
              Sasi               4
              Suresh 3

But if I am trying to do same in power bi the index variables are not displaying. Please help to find this.

 

 Rating
    5
    5
    2
    1
    3

 

The input dataset csv is below

 

movieID,user,Rating
1,Ganesh,5
1,Mithun,3
2,Sasi,4
1,Musthafa,3
2,Suresh,3
1,Shafi,4
1,Kevin,1
2,Jack,5
1,Jayaram,2
1,Ali,5

Please help me to find why the index variables are disappearing in power bi

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: Pivot table using Python facing issue - Index variables are not visible

@pg-gopinathan ,

 

Based on my test, I'm afraid power bi doesn't support index columns in pandas table. As a workaround, you can achieve the same result by using "Pivot" and "Unpivot" in power query.

 

Firstly click "movieID" and "user" column, click transform-> Pivot Columns, select "Rating" as value, sum as  aggregation, you will achieve table like below:

1.PNG 

 

Secondly, click on column "1" and "2" then click "Unpivot Columns":

2.PNG 

 

After reordering the columns and renaming the column headers, you will achieve the result:

3.PNG 

 

Regards,

Jimmy Tao

View solution in original post

2 REPLIES 2
Community Support
Community Support

Re: Pivot table using Python facing issue - Index variables are not visible

@pg-gopinathan ,

 

Based on my test, I'm afraid power bi doesn't support index columns in pandas table. As a workaround, you can achieve the same result by using "Pivot" and "Unpivot" in power query.

 

Firstly click "movieID" and "user" column, click transform-> Pivot Columns, select "Rating" as value, sum as  aggregation, you will achieve table like below:

1.PNG 

 

Secondly, click on column "1" and "2" then click "Unpivot Columns":

2.PNG 

 

After reordering the columns and renaming the column headers, you will achieve the result:

3.PNG 

 

Regards,

Jimmy Tao

View solution in original post

pg-gopinathan
Frequent Visitor

Re: Pivot table using Python facing issue - Index variables are not visible

Thank you Jimmy for the fast response and clarified answer. I will try the same then. 

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors