Pandas provide a method to make Calculation of MAD (Mean Absolute Deviation) very easy. MAD is defined as average distance between each value and mean.
The formula used to calculate MAD is:
Syntax: Series.mad(axis=None, skipna=None, level=None)
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
In this example, a Series is created from a Python List using Pandas .Series() method. The .mad() method is called on series with all default parameters.
Calculating Mean of series 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)
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Absolute Deviation and Absolute Mean Deviation using NumPy | Python
- Create the Mean and Standard Deviation of the Data of a Pandas Series
- How to Plot Mean and Standard Deviation in Pandas?
- Compute the mean, standard deviation, and variance of a given NumPy array
- Calculate the average, variance and standard deviation in Python using NumPy
- Calculate standard deviation of a dictionary in Python
- Calculate pooled standard deviation in Python
- Calculate standard deviation of a Matrix in Python
- Python | Pandas Series.mean()
- Add a Pandas series to another Pandas series
- Calculate the number of characters in each word in a Pandas series
- Calculate the frequency counts of each unique value of a Pandas series
- Calculate the mean across dimension in a 2D NumPy array
- Python | Pandas series.cumprod() to find Cumulative product of a Series
- Python | Pandas Series.str.replace() to replace text in a series
- Python | Pandas Series.astype() to convert Data type of series
- Python | Pandas Series.cumsum() to find cumulative sum of a Series
- Python | Pandas series.cummax() to find Cumulative maximum of a series
- Python | Pandas Series.cummin() to find cumulative minimum of a series
- Python | Pandas Series.nonzero() to get Index of all non zero values in a series
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai