Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas: How to get the average of all averages in pandas after groupby

I am working in Pandas and below is the dataframe

# initialize list of lists
data = [['A','Excel','1'], ['A','Word','0'], ['A','Java','1'],['B','Excel','1'],['B','Word','0'],['C','Word','0'],['D','Java','1'],['E','PPT','0'], ['E','Word','0'], ['E','Java','1']]
  
# Create the pandas DataFrame
df = pd.DataFrame(data, columns=['System','App','DevTool'])

I obtained the DevTool average for each system using below but how can I get the total average of all averages

df.groupby('System')['DevTool'].mean()*100
System DevTool Ratio
A 66.67
B 50.00
C 00.00
D 100.00
E 33.33

Please advice.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you can use:

# initialize list of lists
data1 = [['A','Excel','1'], ['A','Word','0'], ['A','Java','1'],['B','Excel','1'],['B','Word','0'],['C','Word','0'],['D','Java','1'],['E','PPT','0'], ['E','Word','0'], ['E','Java','1']]

# Create the pandas DataFrame
dfdf = pd.DataFrame(data1, columns=['System','App','DevTool'])

#average  System
dfdf['DevTool'] = dfdf['DevTool'].astype('int')
PVT_T = dfdf.pivot_table(index='System', aggfunc={'DevTool':np.mean})

#average all DevTool
dfdf['DevTool'].mean()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading