でシンプルな行にデータフレームの複雑な行を分割:は、私はこのコードを持っているPyspark
from pyspark import SparkContext
from pyspark.sql import SQLContext, Row
sc = SparkContext()
sqlContext = SQLContext(sc)
documents = sqlContext.createDataFrame([
Row(id=1, title=[Row(value=u'cars', max_dist=1000)]),
Row(id=2, title=[Row(value=u'horse bus',max_dist=50), Row(value=u'normal bus',max_dist=100)]),
Row(id=3, title=[Row(value=u'Airplane', max_dist=5000)]),
Row(id=4, title=[Row(value=u'Bicycles', max_dist=20),Row(value=u'Motorbikes', max_dist=80)]),
Row(id=5, title=[Row(value=u'Trams', max_dist=15)])])
documents.show(truncate=False)
#+---+----------------------------------+
#|id |title |
#+---+----------------------------------+
#|1 |[[1000,cars]] |
#|2 |[[50,horse bus], [100,normal bus]]|
#|3 |[[5000,Airplane]] |
#|4 |[[20,Bicycles], [80,Motorbikes]] |
#|5 |[[15,Trams]] |
#+---+----------------------------------+
「ID」を保持したまま、私は得るために、複数の行に、すべての化合物の行(例えば2 & 4)を分割する必要があります次のような結果が得られます。
#+---+----------------------------------+
#|id |title |
#+---+----------------------------------+
#|1 |[1000,cars] |
#|2 |[50,horse bus] |
#|2 |[100,normal bus] |
#|3 |[5000,Airplane] |
#|4 |[20,Bicycles] |
#|4 |[80,Motorbikes] |
#|5 |[15,Trams] |
#+---+----------------------------------+
私が構築していたアイデアです。「タイトル」カテゴリの各要素にIDを取得し(たとえば、各複合行に 'value'、' max_dist'、 'id'を含むようにして)、' flatMap'を実行します。 'map'は入力と出力の間に1対1の関係があるので、' map'を使用することはできません。私は時間があれば、後で答えを出すでしょう! –
ありがとう@Katyaハンドラー、私はあなたのアイデアを試してみます。もし私ができなかったら、私はあなたの助けを借りてコメントします:-) –