Some important math operations can be performed on pandas series for simplifying data analysis using Python and saving time in Data Science.
Now let us look at some functions and their uses.
- s.sum() – This will return the sum of all the values in the series.
- s.mean() – It will return the mean of all values in series. This is equal to s.sum() and s.count().
- s.std() – It will return the standard deviation of all values.
- s.min() or s.max() – It will return the min or max values from the series.
- s.idmin() or s.idmax() – This will return index of min or max value in series.
- s.median() – It will return the median of all values.
- s.mode – It will return the mode of the series.
- s.value_counts() – It will return the series with the frequency of each value.
- s.describe() – It will return a series with information like mean, mode, etc. which depends on the dtype of the data passed.
Unexpected Outputs and Restrictions:
- .sum(), .mean(), .mode(), .median() and other mathematical operations do not apply on string or any other data type other than numeric value.
- .sum() on a string series will give unexpected output, and it will return a string by concatenation of every string.