Skip to content
Advertisement

Plotting CDF of a pandas series in python

Is there a way to do this? I cannot seem an easy way to interface pandas series with plotting a CDF.

Advertisement

Answer

In case you are also interested in the values, not just the plot.

JavaScript

This will always work (discrete and continuous distributions)

JavaScript
JavaScript

enter image description here

JavaScript

enter image description here

Alternative example with a sample drawn from a continuous distribution or you have a lot of individual values:

JavaScript
JavaScript
JavaScript

enter image description here

For continuous distributions only

Please note if it is very reasonable to make the assumption that there is only one occurence of each value in the sample (typically encountered in the case of continuous distributions) then the groupby() + agg('count') is not necessary (since the count is always 1).

In this case, a percent rank can be used to get to the cdf directly.

Use your best judgment when taking this kind of shortcut! :)

JavaScript
JavaScript
JavaScript

enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement