本文簡要介紹
pyspark.RDD.histogram
的用法。用法:
RDD.histogram(buckets)
使用提供的存儲桶計算直方圖。除了最後一個是關閉的,桶都向右打開。例如[1,10,20,50] 表示桶是 [1,10) [10,20) [20,50],表示 1<=x<10, 10<=x<20, 20<=x< =50。在 1 和 50 的輸入上,我們將得到 1,0,1 的直方圖。
如果您的直方圖是均勻分布的(例如 [0, 10, 20, 30]),則可以將每個元素的 O(log n) 插入切換為 O(1)(其中 n 是存儲桶的數量)。
存儲桶必須經過排序,不包含任何重複項,並且至少包含兩個元素。
如果
buckets
是一個數字,它將生成在 RDD 的最小值和最大值之間均勻分布的桶。例如,如果最小值為 0,最大值為 100,給定buckets
為 2,則生成的桶將為 [0,50) [50,100]。buckets
必須至少為 1。如果 RDD 包含無窮大,則會引發異常。如果 RDD 中的元素沒有變化(max == min),則將使用單個存儲桶。返回值是一個桶和直方圖的元組。
例子:
>>> rdd = sc.parallelize(range(51)) >>> rdd.histogram(2) ([0, 25, 50], [25, 26]) >>> rdd.histogram([0, 5, 25, 50]) ([0, 5, 25, 50], [5, 20, 26]) >>> rdd.histogram([0, 15, 30, 45, 60]) # evenly spaced buckets ([0, 15, 30, 45, 60], [15, 15, 15, 6]) >>> rdd = sc.parallelize(["ab", "ac", "b", "bd", "ef"]) >>> rdd.histogram(("a", "b", "c")) (('a', 'b', 'c'), [2, 2])
相關用法
- Python pyspark RDD.saveAsTextFile用法及代碼示例
- Python pyspark RDD.keyBy用法及代碼示例
- Python pyspark RDD.sumApprox用法及代碼示例
- Python pyspark RDD.lookup用法及代碼示例
- Python pyspark RDD.zipWithIndex用法及代碼示例
- Python pyspark RDD.sampleByKey用法及代碼示例
- Python pyspark RDD.coalesce用法及代碼示例
- Python pyspark RDD.subtract用法及代碼示例
- Python pyspark RDD.count用法及代碼示例
- Python pyspark RDD.groupWith用法及代碼示例
- Python pyspark RDD.distinct用法及代碼示例
- Python pyspark RDD.treeAggregate用法及代碼示例
- Python pyspark RDD.mapPartitionsWithIndex用法及代碼示例
- Python pyspark RDD.foreachPartition用法及代碼示例
- Python pyspark RDD.zipWithUniqueId用法及代碼示例
- Python pyspark RDD.sortByKey用法及代碼示例
- Python pyspark RDD.takeOrdered用法及代碼示例
- Python pyspark RDD.collectAsMap用法及代碼示例
- Python pyspark RDD.countApproxDistinct用法及代碼示例
- Python pyspark RDD.toLocalIterator用法及代碼示例
- Python pyspark RDD.reduceByKeyLocally用法及代碼示例
- Python pyspark RDD.max用法及代碼示例
- Python pyspark RDD.map用法及代碼示例
- Python pyspark RDD.partitionBy用法及代碼示例
- Python pyspark RDD.stdev用法及代碼示例
注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.RDD.histogram。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。