Cou*_*unt 19 dataframe apache-spark apache-spark-sql
我有一个Spark数据帧,其列数非常滞后我想从中删除两列以获得新的数据帧
如果列数较少,我可以使用API中的select方法
pcomments = pcomments.select(pcomments.col("post_id"),pcomments.col("comment_id"),pcomments.col("comment_message"),pcomments.col("user_name"),pcomments.col("comment_createdtime"));
Run Code Online (Sandbox Code Playgroud)
但是,从长列表中选择列是一项繁琐的工作,是否有解决方法.
小智 30
使用drop方法和withColumnRenamed方法.
例:
val initialDf= ....
val dfAfterDrop=initialDf.drop("column1").drop("coumn2")
val dfAfterColRename= dfAfterDrop.withColumnRenamed("oldColumnName","new ColumnName")
Run Code Online (Sandbox Code Playgroud)
Man*_*akd 10
尝试这个:
val initialDf = ...
val dfAfterDropCols = initialDf.drop("column1", "coumn2")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26027 次 |
| 最近记录: |