gpt4 book ai didi

python - 在 python 中绘制 Pandas 系列的 CDF

转载 作者:IT老高 更新时间:2023-10-28 21:43:38 25 4
gpt4 key购买 nike

有没有办法做到这一点?将 Pandas 系列与绘制 CDF 连接起来似乎不是一种简单的方法。

最佳答案

我相信您正在寻找的功能是在一个 Series 对象的 hist 方法中,该方法将 hist() 函数包装在 matplotlib 中

这是相关文档

In [10]: import matplotlib.pyplot as plt

In [11]: plt.hist?
...
Plot a histogram.

Compute and draw the histogram of *x*. The return value is a
tuple (*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*,
[*patches0*, *patches1*,...]) if the input contains multiple
data.
...
cumulative : boolean, optional, default : False
If `True`, then a histogram is computed where each bin gives the
counts in that bin plus all bins for smaller values. The last bin
gives the total number of datapoints. If `normed` is also `True`
then the histogram is normalized such that the last bin equals 1.
If `cumulative` evaluates to less than 0 (e.g., -1), the direction
of accumulation is reversed. In this case, if `normed` is also
`True`, then the histogram is normalized such that the first bin
equals 1.

...

例如

In [12]: import pandas as pd

In [13]: import numpy as np

In [14]: ser = pd.Series(np.random.normal(size=1000))

In [15]: ser.hist(cumulative=True, density=1, bins=100)
Out[15]: <matplotlib.axes.AxesSubplot at 0x11469a590>

In [16]: plt.show()

关于python - 在 python 中绘制 Pandas 系列的 CDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25577352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com