我已经看到很多人建议 Dataframe.explode
是一种有用的方法,但是它会导致比原始数据框架更多的行,这根本不是我想要的。我只是想在数据框架中做一些非常简单的事情:
rdd.map(lambda row: row + [row.my_str_col.split('-')])
看起来就像:
col1 | my_str_col
-----+-----------
18 | 856-yygrm
201 | 777-psgdg
然后转换成这个:
col1 | my_str_col | _col3 | _col4
-----+------------+-------+------
18 | 856-yygrm | 856 | yygrm
201 | 777-psgdg | 777 | psgdg
我知道 pyspark.sql.functions.split()
,但是它导致嵌套的数组列,而不是我想要的两个顶级列。
理想情况下,我希望这些新列也被命名。