[英]Pyspark: Select all columns except particular columns
I have a large number of columns in a PySpark dataframe, say 200. I want to select all the columns except say 3-4 of the columns.我在 PySpark dataframe 中有大量列,比如 200。我想 select 除了说 3-4 列之外的所有列。 How do I select this columns without having to manually type the names of all the columns I want to select?我如何 select 这个列而不必手动键入我想要 select 的所有列的名称?
df.drop(*[cols for cols in [list of columns to drop]])
Useful if the list to drop columns is huge.如果要删除列的列表很大,则很有用。 or if the list can be derived programmatically.或者该列表是否可以通过编程方式派生。
I have a large number of columns in a PySpark dataframe, say 200. I want to select all the columns except say 3-4 of the columns.我在 PySpark 数据框中有大量列,比如 200。我想选择除 3-4 列之外的所有列。 How do I select this columns without having to manually type the names of all the columns I want to select?如何选择此列而不必手动键入要选择的所有列的名称?
df_cols = list(set(df.columns) - {'<col1>','<col2>',....})
df.select(df_cols).show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.