python Pandas : How I can determine the distribution of my dataset?

标签 python pandas plot histogram

这是我的数据集,包含两列 NS 和计数。

    NS                                                count
0   ns18.dnsdhs.com.                                  1494
1   ns0.relaix.net.                                   1835
2   ns2.techlineindia.com.                            383
3   ns2.microwebsys.com.                              1263
4   ns2.holy-grail-body-transformation-program.com.   1
5   ns2.chavano.com.                                  1
6   ns1.x10host.ml.                                   17
7   ns1.amwebaz.info.                                 48
8   ns2.guacirachocolates.com.br.                     1
9   ns1.clicktodollars.com.                           2

现在我想通过绘制它来查看有多少个 NS 具有相同的计数。我自己的猜测是我可以使用直方图来查看,但我不确定如何。谁能帮忙?

最佳答案

根据您的评论,我猜您的数据表实际上要长得多,并且您想查看名称服务器 counts 的分布(无论此处为多少)。

我认为你应该能够做到这一点:

df.hist(column="count")

你会得到你想要的。如果那是你想要的。

pandas 的所有功能都有不错的文档,并且描述了直方图 here .

如果你真的想看到“有多少人有相同的计数”,而不是分布的表示,那么你要么需要将 bins kwarg 设置为 df ["count"].max()-df["count"].min() - 或者按照你说的做,计算你得到每个 count 的次数,然后创建条形图。

也许是这样的:

from collections import Counter
counts = Counter()
for count in df["count"]:
  counts[count] += 1

print counts

另一种更简洁的方法,我完全错过了,第二次世界大战在下面指出,就是使用 Counter 的标准构造函数:

count_counter = Counter(df['count'])

关于 python Pandas : How I can determine the distribution of my dataset?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28585367/

相关文章:

python - 使用 python 将重复键添加到 JSON

python argparse 处理任意数字选项(如 HEAD(1))

python - pandas dataframe view vs copy,我怎么知道?

python - 使用 pandas.plot 在 python 中自定义直方图中 x 轴的值

python - 计算 pandas 数据框中的加权平均值

python - 如何在 Selenium 中正确启动 Chrome

python - gae、python、onesignal --- onesignal 玩家标签不会在仪表板上更新?

python - 尝试在 matplotlib 中绘制蜘蛛网图时出现错误结果

matlab - 在 MATLAB 中绘制体积数据

python - 如何使用 Spyder 在 Python 中设置绘图的纵横比?