Mithil Amin
Mithil Amin

Reputation: 207

How to plot pivot chart in python?

Currenly, I am new in python scripting I am using panda, pivottablejs for creating a script. I have one csv file and I read that csv file using panda and I got the table like this. enter image description here

Now, I want to generate the pivotchart using pivottablejs so for that I have to pass dataframe object in the pivot_ui();

I want to Plot in Pivot Chart the total number of issue status created for every OriginationPhase.

So I tried something like this.

LabelsReviewedByDate = issues_df.groupby(['Status','OriginationPhase'])

pivot_ui(LabelsReviewedByDate)

I know this is wrong but I am new in python scripting. So help me to find the solution.

Thank you

Upvotes: 2

Views: 13982

Answers (2)

Andrew L
Andrew L

Reputation: 7038

You can just pass the dataframe right to pivot_ui:

import pandas as pd
from pivottablejs import pivot_ui

a= [ [1,'Requirements','bug'],[2,'Design','bug'],[3,'Testing','bug'],[4,'Requirements','bug'],[5,'Requirements','Inquiry'] ]

df  = pd.DataFrame(a,columns =['Issue#','OriginationPhase','Category'])

pivot_ui(df)

enter image description here

Upvotes: 3

galaxyan
galaxyan

Reputation: 6121

The pivot_table method comes to solve this problem. It works like pivot, but it aggregates the values from rows with duplicate entries for the specified columns

a= [ [1,'Requirements','bug'],[2,'Design','bug'],[3,'Testing','bug'],[4,'Requirements','bug'],[5,'Requirements','Inquiry'] ]

df  = pd.DataFrame(a,columns =['Issue#','OriginationPhase','Category'])
df.pivot_table( index = 'Category',columns = 'OriginationPhase',aggfunc = lambda x: len(x) )  )

                 Issue#                     
OriginationPhase Design Requirements Testing
Category                                    
Inquiry             NaN            1     NaN
bug                   1            2       1

Upvotes: 1

Related Questions