Change language

Python | Pandas Series.mad () to calculate the mean absolute deviation of a series

| | | |

Formula used to calculate MAD:

Syntax: Series.mad (axis = None, skipna = None, level = None)

Parameters:
axis: 0 or ’index’ for row wise operation and 1 or ’columns’ for column wise operation.
skipna: Includes NaN values ​​too if False, Result will also be NaN even if a single Null value is included.
level: Defines level name or number in case of multilevel series.

Return Type: Float value

Example # 1:
B This example creates a Series from a Python list using the Pandas .Series () method. The .mad () method is called for a series with all default parameters.

# pandas module import

import pandas as pd 

 
# numpy module import

import numpy as np 

 
# create a list

list = [ 5 , 12 , 1 , 0 , 4 , 22 , 15 , 3 , 9 ]

 
# create series

series = pd.Series ( list )

 
# method call .mad ()

result = series.mad ()

 
# display
result

Output:

5.876543209876543

Explanation :

Calculating Mean of serie s mean = (5 + 12 + 1 + 0 + 4 + 22 + 15 + 3 + 9) / 9 = 7.8888

MAD = | (5-7.88) + (12-7.88) + (1-7.88) + (0-7.88) + (4-7.88) + (22-7.88) + (15-7.88) + (3-7.88) + (9 -7.88)) | / 9.00

MAD = (2.88 + 4.12 + 6.88 + 7.88 + 3.88 + 14.12 + 7.12 + 4.88 + 1.12) / 9.00

MAD = 5.8755 (More accurately = 5.876543209876543)

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method