Change language

Python | Pandas Dataframe.describe () method

Pandas describe() are used to view some basic statistics such as percentile, mean, standard deviation, etc. of a data frame or series of numeric values. When this method is applied to a sequence of lines, it returns different output as shown in the examples below.

Syntax: DataFrame.describe (percentiles = None, include = None, exclude = None)

Parameters:
percentile: list like data type of numbers between 0-1 to return the respective percentile
include: List of data types to be included while describing dataframe. Default is None
exclude: List of data types to be Excluded while describing dataframe. Default is None

Return type: Statistical summary of data frame.

To load the dataset used in the following example, press here.
In the following examples, the data frame used contains data for some NBA players. An image of the data frame before any operations is attached below. 

Example # 1: Describing a data frame as an object, and with a numeric data type

This example describes a data frame and passes [& # 39; object & # 39;] to include an option to see a description of a series of objects. [.20, .40, .60, .80] is passed to the percentile parameter to view the corresponding percentile of the number series.

# pandas module import

import pandas as pd 

 
# regex module import

import re

  
# create data frame

data = pd.read_csv ( " https://media.python.engineering / wp-content / uploads / nba.csv "

< code class = "undefined spaces">  
# remove null values ​​to avoid errors

data.dropna (inplace = True

 
# percentile list

perc = [. 20 ,. 40 ,. 60 ,. 80 ]

 
# list of dtypes to include

include = [ ’object’ , ’ float’ , ’int’ ]

 
# call the description method

desc = data.describe (percentiles = perc, include = include)

 
# display
desc

Output:
As shown on the output image, a statistical description of the data frame is returned with the corresponding missing percentiles. For columns with strings, NaN was returned for numeric operations. 

Example # 2: Description of a series of lines

This example calls the description method on the Name column to see behavior with the object’s data type.

# pandas module import

import pandas as pd 

  
# regex module import

import re

 
# create data frame

data = pd.read_csv ( " https://media.python.engineering/wp-content/uploads/nba.csv "

 
# remove null values ​​to avoid errors

data.dropna (inplace = True

 
# call description method

desc = data [ "Name" ]. Describe ()

 
# display
desc

Output:
As shown in the output image, the behavior of description () differs from a sequence of lines. 
In this case, various characteristics were returned, such as number of values, unique values, top and frequency of occurrence. 

Shop

Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best laptop for development

$499+
Gifts for programmers

Best laptop for Cricut Maker

$299+
Gifts for programmers

Best laptop for hacking

$890
Gifts for programmers

Best laptop for Machine Learning

$699+
Gifts for programmers

Raspberry Pi robot kit

$150

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically