例如: mydataframe有2列和1行
val df = Seq(("1,2,3", "tom")).toDF("id", "name")
ids(String) name(String)
1,2,3 tom
在transform =>
之后我希望df等于
Seq(("1", "tom"), ("2", "tom"), ("3", "tom")).toDF("id", "name")
ids name
1 tom
2 tom
3 tom
我看到有一个具有以下签名的explode()函数:
public <A extends scala.Product> DataFrame explode(scala.collection.Seq<Column> input,
scala.Function1<Row,scala.collection.TraversableOnce<A>> f,
scala.reflect.api.TypeTags.TypeTag<A> evidence$1)
答案 0 :(得分:0)
尝试
from pyspark.sql.functions import explode
df.select(explode(df.ids).alias('ids'), name).collect()