2024-06-26 10:03:36 发布
网友
我有这样的数据帧:
+----------+---+ | code |idn| +----------+---+ | [I0478]| 0| | [B0527]| 1| | [C0798]| 2| | [C0059]| 3| | [I0767]| 4| | [I1001]| 5| | [C0446]| 6| +----------+---+
我想向DataFrame添加新列
请帮帮我!在
使用[]:
[]
df.withColumn("item", df["item"][0])
df.withColumn("item", df["code"][0])
如果“item”列是数组类型,如果是string结构,则可能需要通过数据框选择(“code”).collect()[0],查看它有什么键(字符串)。在
使用
[]
:如果“item”列是数组类型,如果是string结构,则可能需要通过数据框选择(“code”).collect()[0],查看它有什么键(字符串)。在
相关问题 更多 >
编程相关推荐