Create the Mean and Standard Deviation of the Data of a Pandas Series

Standard Deviation is the square root of the Variance. The Standard Deviation denoted by sigma is a measure of the spread of numbers. In pandas, the std() function is used to find the standard Deviation of the series.
The mean can be simply defined as the average of numbers. In pandas, the mean() function is used to find the mean of the series.

Example 1 : Finding the mean and Standard Deviation of a Pandas Series.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import pandas as pd
  
# creating a series
s = pd.Series(data = [5, 9, 8, 5, 7, 8, 1, 2, 3,
                      4, 5, 6, 7, 8, 9, 5, 3])
  
# displaying the series
print(s)

chevron_right


Output :

Finding the mean of the series using the mean() function.

filter_none

edit
close

play_arrow

link
brightness_4
code

# finding the mean
print(s.mean())

chevron_right


Output :



Finding the standard deviation of the series using the std() function.

filter_none

edit
close

play_arrow

link
brightness_4
code

# finding the Standard deviation
print(s.std())

chevron_right


Output :

Example 2 : Finding the mean and Standard Deviation of a Pandas DataFrame.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import pandas as pd
  
# creating a dataframe 
df = pd.DataFrame({'ID':[114, 345, 157788, 5626],
                   'Product':['shirt', 'trousers', 'tie', 'belt'],
                   'Color':['White', 'Black', 'Red', 'Brown'],
                   'Discount':[10, 10, 10, 10]})
  
# displaying the DataFrame
print(df)

chevron_right


Output :

Finding the mean of the DataFrame using the mean() function.

filter_none

edit
close

play_arrow

link
brightness_4
code

# finding the mean
print(df.mean())

chevron_right


Output :

Finding the standard deviation of the DataFrame using the std() function.

filter_none

edit
close

play_arrow

link
brightness_4
code

# finding the Standard deviation
print(df.std())

chevron_right


Output :

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.




My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :

    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.