我在一个有columns>2000号的表上工作,我想执行表中所有数字列的统计,我创建了一个
df =sqlContext.sql(“从表中选择*”)
我试着在dataframe上使用describe()作为df.describe(),但这就像进程正在为终身运行.持续了5-6个小时,但没有反应。
有人能帮我解决这个问题吗?提前谢谢。
在scala中有一个叫做滑动的函数,可以作为allColumns.sliding(200)使用,它可以滑动200列,而且我们可以执行该列的avg。
此外,我还需要收集所有的部分,即P1 -> 1-200列,P2 -> 201-400等,并将它们连接起来,共同获取数据。
发布于 2017-04-20 15:46:40
可以直接计算sql请求中的平均值,如下所示:
# collect the column name and shape then in a list
colname = sqlContext.sql("describe table1").select("col_name").collect()
colname = [x.col_name for x in colname]
# build the query (average on each column)
df = sqlContext.sql("select " +",".join(["AVG({0}) AS avg_{0}".format(x) for x in colname]) + " from table")
# As a result you will get the average for each column (as Row)
df.collect()不一定要回答你的问题。不要犹豫,评论。
https://stackoverflow.com/questions/43512407
复制相似问题