w3resource

Pandas Data Series: Create the mean and standard deviation of the data of a given Series

Pandas: Data Series Exercise-15 with Solution

Write a Pandas program to create the mean and standard deviation of the data of a given Series.

Sample Solution :

Python Code :

import pandas as pd
s = pd.Series(data = [1,2,3,4,5,6,7,8,9,5,3])
print("Original Data Series:")
print(s)
print("Mean of the said Data Series:")
print(s.mean())
print("Standard deviation of the said Data Series:")
print(s.std())

Sample Output:

Original Data Series:
0     1
1     2
2     3
3     4
4     5
5     6
6     7
7     8
8     9
9     5
10    3
dtype: int64
Mean of the said Data Series:
4.818181818181818
Standard deviation of the said Data Series:
2.522624895547565                 

Explanation:

In the above code –

s = pd.Series(data = [1,2,3,4,5,6,7,8,9,5,3]): This line creates a Pandas Series object 's' containing a sequence of 11 integer values.print(s.mean()): This line calculates the mean of the values in the Pandas Series object 's' using the .mean() method and prints the result.

print(s.std()): This line calculates the standard deviation of the values in the Pandas Series object 's' using the .std() method and prints the result. The standard deviation is a measure of the spread of the data and is calculated by taking the square root of the average of the squared differences from the mean.

Python-Pandas Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to change the order of index of a given series.
Next: Write a Pandas program to get the items of a given series not present in another given series.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.