擅长:python、mysql、java
<p>您在问题中定义的选择不会产生您提到的结果。我想你忘了从数组中选择元素;)</p>
<pre><code>users1 = [F.split(F.col(x), "\\|:\\|").alias(x) for x in cols]
dd1.select(*users1).show()
+ + + + +
| Id| col1| col2| col3|
+ + + + +
|[1A]|[Not his side, Th...| [This side]|[Not this either,...|
|[1B]| [Keep this]|[This one, keep t...| [remove, keep that]|
+ + + + +
</code></pre>
<p>要实现所需的功能,只需选择数组的最后一个元素。您可以使用size函数:</p>
<pre><code>users2 = [F.col(x).getItem(F.size(F.col(x))-1).alias(x) for x in cols]
dd1.select(*users1).select(*users2).show()
+ -+ -+ -+ -+
| Id| col1| col2| col3|
+ -+ -+ -+ -+
| 1A|This side|This side| but this|
| 1B|Keep this|keep this|keep that|
+ -+ -+ -+ -+
</code></pre>