pyspark中groupBy之后的列别名 [英] Column alias after groupBy in pyspark

查看:933
本文介绍了pyspark中groupBy之后的列别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要下面一行中的结果数据框,以便在groupBy之后的max('diff')列中使用别名名称"maxDiff".但是,以下行不会进行任何更改,也不会引发错误.

I need the resulting data frame in the line below, to have an alias name "maxDiff" for the max('diff') column after groupBy. However, the below line does not makeany change, nor throw an error.

 grpdf = joined_df.groupBy(temp1.datestamp).max('diff').alias("maxDiff")

推荐答案

这是因为您要为整个DataFrame对象而不是Column加上别名.这是一个仅对Column进行别名的示例:

This is because you are aliasing the whole DataFrame object, not Column. Here's an example how to alias the Column only:

import pyspark.sql.functions as func

grpdf = joined_df \
    .groupBy(temp1.datestamp) \
    .max('diff') \
    .select(func.col("max(diff)").alias("maxDiff"))

这篇关于pyspark中groupBy之后的列别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆