简体   繁体   English

如何使用另一个数据帧的值创建数据帧

[英]How to create a dataframe using the value of another dataframe

I am getting suppId DataFrame using below code.我使用以下代码获取 suppId DataFrame。

val suppId = sqlContext.sql("SELECT supp_id FROM supplier")

The DataFrame return single or multiple value. DataFrame 返回单个或多个值。

Now I want to create a DataFrame using the value of supp_id from suppId DataFrame.现在我想使用来自 suppId DataFrame 的 supp_id 的值创建一个 DataFrame。 But not understand, how to write this.但是不明白,这个怎么写。

I have written below code.我写了下面的代码。 But the code is not working.但是代码不起作用。

val nonFinalPE = sqlContext.sql("select * from pmt_expr) 
nonFinalPE.where("supp_id in suppId(supp_id)")

It took me a second to figure out what you're trying to do.我花了一秒钟才弄清楚你要做什么。 But, it looks like you want rows from nonFinalPe that are also in suppId.但是,看起来您希望来自 nonFinalPe 的行也在 suppId 中。 You'd get this by doing an inner join of the two data frames which would look like below您可以通过对两个数据框进行内部连接来获得此信息,如下所示

val suppId = sqlContext.sql("SELECT supp_id FROM supplier")
val nonFinalPE = sqlContext.sql("select * from pmt_expr") 

val joinedDF = nonFinalPE.join(suppId, nonFinalPE("???") === suppId("supp_id"), "inner")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM