将数据帧结果值保存到字符串变量? [英] Saving a dataframe result value to a string variable?
本文介绍了将数据帧结果值保存到字符串变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当找到我想将其保存到变量的最大日期时,我在 spark 中创建了一个数据框.只是想弄清楚如何得到结果,这是一个字符串,并将其保存到一个变量中.
I created a dataframe in spark when find the max date I want to save it to the variable. Just trying to figure out how to get the result, which is a string, and save it to a variable.
到目前为止的代码:
sqlDF = spark.sql("SELECT MAX(date) FROM account")
sqlDF.show()
结果是什么样的:
+--------------------+
| max(date)|
+--------------------+
|2018-04-19T14:11:...|
+--------------------+
谢谢
推荐答案
尝试这样的事情:
from pyspark.sql.functions import max as max_
# get last partition from all deltas
alldeltas=sqlContext.read.json (alldeltasdir)
last_delta=alldeltas.agg(max_("ingest_date")).collect()[0][0]
last_delta 会给你一个值,在这个示例中是数据帧中列 ingest_date 的最大值.
last_delta will give you a value, in this sample the maximum value of the column ingest_date in the dataframe.
这篇关于将数据帧结果值保存到字符串变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文