Python ProgrammingPython Programming

Describe the summary statistics of DataFrame in Pandas

Summary statistics:

import pandas as pd

df = pd.DataFrame([[10, 20, 30, 40], [7, 14, 21, 28], [55, 15, 8, 12],
                   [15, 14, 1, 8], [7, 1, 1, 8], [5, 4, 9, 2]],
                  columns=['Apple', 'Orange', 'Banana', 'Pear'],
                  index=['Basket1', 'Basket2', 'Basket3', 'Basket4',
                         'Basket5', 'Basket6'])

print("\n----------- Describe DataFrame -----------\n")
print(df.describe())

print("\n----------- Describe Column -----------\n")
print(df[['Apple']].describe())


C:\pandas>python example.py
 
----------- Describe DataFrame -----------
 
           Apple     Orange     Banana       Pear
count   6.000000   6.000000   6.000000   6.000000
mean   16.500000  11.333333  11.666667  16.333333
std    19.180719   7.257180  11.587349  14.555640
min     5.000000   1.000000   1.000000   2.000000
25%     7.000000   6.500000   2.750000   8.000000
50%     8.500000  14.000000   8.500000  10.000000
75%    13.750000  14.750000  18.000000  24.000000
max    55.000000  20.000000  30.000000  40.000000
 
----------- Describe Column -----------
 
           Apple
count   6.000000
mean   16.500000
std    19.180719
min     5.000000
25%     7.000000
50%     8.500000
75%    13.750000
max    55.000000
 
C:\pandas>