pandas - 使用 TopN 与考拉进行绘图有任何统计意义吗?
问题描述
我正在浏览Koalas的源代码,试图了解它们如何真正实现绘制大型数据集。事实证明,他们要么使用抽样,要么使用TopN
- 选择给定数量的记录。
我了解采样的含义,并且在内部使用它spark.DataFrame.sample
来执行此操作。但是,对于TopN
,他们只是max_rows
使用data = data.head(max_rows + 1).to_pandas()
.
这看起来很奇怪,我想知道它是否正确反映了以这种方式进行数据选择的数据集的统计属性。
Koalas DataFrame 的绘图访问器:
class KoalasPlotAccessor(PandasObject):
pandas_plot_data_map = {
"pie": TopNPlotBase().get_top_n,
"bar": TopNPlotBase().get_top_n,
"barh": TopNPlotBase().get_top_n,
"scatter": SampledPlotBase().get_sampled,
"area": SampledPlotBase().get_sampled,
"line": SampledPlotBase().get_sampled,
}
_backends = {} # type: ignore
...
class TopNPlotBase:
def get_top_n(self, data):
from databricks.koalas import DataFrame, Series
max_rows = get_option("plotting.max_rows")
# Simply use the first 1k elements and make it into a pandas dataframe
# For categorical variables, it is likely called from df.x.value_counts().plot.xxx().
if isinstance(data, (Series, DataFrame)):
data = data.head(max_rows + 1).to_pandas()
...
解决方案
推荐阅读
- graphql - 动态加载字段
- php - 如何将 Pusher Laravel Echo 与 SharedWorkers 一起使用?
- gem5 - gem5 卡在 gues 操作系统登录页面?
- django - 当数据库从其他应用程序获取更新时,如何实时更新前端?
- sql - 选择与另一个表无关的产品
- angular - Asp.net Core 对 Angular 材料表的响应
- php - WP_Query($args) 在 Wordpress 中不起作用
- powershell - 使用 Powershell 提取 Active Directory 中的用户列表(百万)
- php - 如果从最高顺序选择了一个值,PHP foreach 循环仅显示选定的选项
- php - 如何从数据库中获取作为模型codeigniter中的数组的数据