我有一个DataFrame
并在上面运行flatMap
。
在map函数中,我试图将一个新字段附加到给定行。在
我怎么能做到呢?在
def mapper(row):
value = 0 #some computation here
row.append(newvalue = value) #??? something like that
return row
data = sqlContext.jsonFile("data.json")
mapped = data.flatMap(mapper)
#do further mappings with the new field
我想出来了,但我不确定这是不是正确的方法。在
在你的领导下,我创造了一些更灵活的方法,我希望它能有所帮助:
要在一行上使用它,只需这样调用:
^{2}$要在整个数据集上运行,只需创建一个udf来更改每一行。在
相关问题 更多 >
编程相关推荐