The plot of the CDF function or cumulative distribution is basically a plot, the x-axis is the sorted values, and the y-axis is the cumulative distribution. So, I would create a new series with sorted values ββas an index and cumulative distribution as values.
First create an example series:
import pandas as pd import numpy as np ser = pd.Series(np.random.normal(size=100))
Series Sort:
ser = ser.sort_values()
Now, before continuing, add the last (and largest) value again. This step is especially important for small sample sizes to get an unbiased CDF:
ser[len(ser)] = ser.iloc[-1]
Create a new series with sorted values ββas an index and cumulative distribution as values:
cum_dist = np.linspace(0.,1.,len(ser)) ser_cdf = pd.Series(cum_dist, index=ser)
Finally, build the function as steps:
ser_cdf.plot(drawstyle='steps')
kadee Aug 12 '15 at 16:57 2015-08-12 16:57
source share