How to Get the Descriptive Statistics for Pandas DataFrame? - GeeksforGeeks

10 Jul, 2020
describe() method in Python Pandas is used to compute descriptive statistical data like count, unique values, mean, standard deviation, minimum and maximum value and many more. In this article, let’s learn to get the descriptive statistics for Pandas DataFrame.
Syntax:df[‘cname’].describe(percentiles = None, include = None, exclude = None)df.describe(percentiles = None, include = None, exclude = None)
Parameters:percentiles: represents percentile value that has to be returned by the function. Default values are 0.25, 0.5 and 0.75include: represents list of data types that has to be includedexclude: represents list of data types that has to be excluded
Example 1:
# Import packagefrom pandas import DataFrame  # Create DataFramecart = {'Product': ['Mobile', 'AC', 'Mobile', 'Sofa', 'Laptop'],        'Price': [20000, 28000, 22000, 19000, 45000],         'Year': [2014, 2015, 2016, 2017, 2018]        }df = DataFrame(cart, columns = ['Product', 'Price', 'Year'])  # Original DataFrameprint("Original DataFrame:\n", df)  # Describing descriptive statistics of Priceprint("\nDescriptive statistics of Price:\n")stats = df['Price'].describe()print(stats)
Output:Example 2:
# Import packagefrom pandas import DataFrame  # Create DataFramecart = {'Product': ['Mobile', 'AC', 'Mobile', 'Sofa', 'Laptop'],        'Price': [20000, 28000, 22000, 19000, 45000],         'Year': [2014, 2015, 2016, 2017, 2018]        }df = DataFrame(cart, columns = ['Product', 'Price', 'Year'])  # Original DataFrameprint("Original DataFrame:\n", df)  # Describing descriptive statistics of Yearprint("\nDescriptive statistics of year:\n")stats = df['Year'].describe()print(stats)
Output:Example 3:
# Import packagefrom pandas import DataFrame  # Create DataFramecart = {'Product': ['Mobile', 'AC', 'Mobile', 'Sofa', 'Laptop'],        'Price': [20000, 28000, 22000, 19000, 45000],         'Year': [2014, 2015, 2016, 2017, 2018]        }df = DataFrame(cart, columns = ['Product', 'Price', 'Year'])  # Original DataFrameprint("Original DataFrame:\n", df)  # Describing descriptive statistics of whole dataframeprint("\nDescriptive statistics of whole dataframe:\n")stats = df.describe(include = 'all')print(stats)
Output:Example 4:In this example, let’s print all the descriptive statistical data individually.
from pandas import DataFrame  # Create DataFramecart = {'Product': ['Mobile', 'AC', 'Mobile', 'Sofa', 'Laptop'],        'Price': [20000, 28000, 22000, 19000, 45000],         'Year': [2014, 2015, 2016, 2017, 2018]        }df = DataFrame(cart, columns = ['Product', 'Price', 'Year'])  # Original DataFrameprint("Original DataFrame:\n", df)  # Print Count of Priceprint("\nCount of Price:\n")counts = df['Price'].count()print(counts)  # Print mean of Priceprint("\nMean of Price:\n")m = df['Price'].mean()print(m)  # Print maximum value of Priceprint("\nMaximum value of Price:\n")mx = df['Price'].max()print(m)  # Print standard deviation of Priceprint("\nStandard deviation of Price:\n")sd = df['Price'].std()print(sd)
Output:
Python pandas-dataFrame
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
Enumerate() in Python
How to Install PIP on Windows ?
Iterate over a list in Python
Different ways to create Pandas Dataframe
Python String | replace()
Create a Pandas DataFrame from Lists
Python program to convert a list to string
Reading and Writing to text files in Python