python - 超出表中每一列的范围计数
问题描述
我正在尝试获取表中所有列的超出范围的值。首先,我根据下面的代码得到超出范围的最大值和最小值,然后尝试遍历表中的所有记录以获取超出范围的每一列的记录数。当表大小很小时,下面的函数效果很好,但是当表大小以十亿为单位时,它需要很长时间才能检查每条记录。当表格很大时,他们是否有更好的方法来获得超出范围的计数。
out_of_range_max_value = spark_df.select([(F.round(F.mean(F.col(c).cast('int')),0) + 3* F.round(F.stddev(F.col(c).cast('int')),0)).alias(c) for c in spark_df.columns if dict(spark_df.dtypes)[c] not in ('timestamp', 'string', 'date','array<string>')])
out_of_range_min_value = spark_df.select([(F.round(F.mean(F.col(c).cast('int')),0) - 3* F.round(F.stddev(F.col(c).cast('int')),0)).alias(c) for c in spark_df.columns if dict(spark_df.dtypes)[c] not in ('timestamp', 'string', 'date','array<string>')])
df = spark_df.agg(*(F.count(F.when((F.col(c).cast('int') > out_of_range_pdfNA[c].astype(int).values.tolist()[0]) | (F.col(c).cast('int') < out_of_range_pdfNA[c].astype(int).values.tolist()[1]), c)).alias(c) for c in spark_df.columns if dict(spark_df.dtypes)[c] not in ('timestamp', 'string', 'date','array<string>') ))
解决方案
推荐阅读
- r - 为不同的热图保持热图颜色范围相同
- c++ - 限制 Concurrency::parallel_for 中使用的线程数
- http - 如何阻止 ReverseProxy 代理请求
- android - 实施 Kapt 在自动生成的改造文件中导致构建错误
- c# - Swagger (Swashbuckle) - 如何在端点下添加文本
- python - 在 Python 中编写一个“棋盘”函数,打印出请求的二进制长度
- python-3.x - 不能多次滚动一个 div | 硒 | Python
- c# - NUnit3TestExecutor 使用当前发现模式发现了 1 个 NUnit 测试用例中的 0 个,显式运行
- android - 拥有 ContentProvider 的进程中的异常崩溃使用 ContentProvider 的进程
- vba - 为什么我需要在使用之前激活工作表