天天看点

[Spark][Python]DataFrame的左右连接例子

[Spark][Python]DataFrame的左右连接例子

$ hdfs dfs -cat people.json

$ hdfs dfs -cat pcodes.json

$pyspark

sqlContext = HiveContext(sc)

peopleDF = sqlContext.read.json("people.json")

peopleDF.limit(5).show()

[Spark][Python]DataFrame的左右连接例子
[Spark][Python]DataFrame的左右连接例子

pcodesDF = sqlContext.read.json("pcodes.json")

pcodesDF.limit(5).show()

[Spark][Python]DataFrame的左右连接例子
[Spark][Python]DataFrame的左右连接例子

mydf000 = peopleDF.join(pcodesDF,"pcode")

mydf000.limit(5).show()

[Spark][Python]DataFrame的左右连接例子
[Spark][Python]DataFrame的左右连接例子

mydf001=peopleDF.join(pcodesDF,"pcode","leftsemi")

mydf001.limit(5).show()

[Spark][Python]DataFrame的左右连接例子
[Spark][Python]DataFrame的左右连接例子

mydf002=peopleDF.join(pcodesDF,"pcode","left_outer")

mydf002.limit(5).show()

[Spark][Python]DataFrame的左右连接例子
[Spark][Python]DataFrame的左右连接例子

mydf003=peopleDF.join(pcodesDF,"pcode","right_outer")

mydf003.limit(5).show()

[Spark][Python]DataFrame的左右连接例子
[Spark][Python]DataFrame的左右连接例子

<a></a>

本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/7633001.html,如需转载请自行联系原作者

继续阅读