简体   繁体   中英

Pyspark dataframe drop columns issue

I am trying to drop two columns from a dataframe but I am facing an error as

**Error:**
drop() takes 2 positional arguments but 3 were given

***Code:***
 excl_columns= row['exclude_columns'].split(',')
 df=df.drop(*excl_columns)

#print(excl_columns)
#['year_of_birth', 'ethnicity']

Here's one way which should work:

excl_columns = row['exclude_columns'].split(',')
df.select([c for c in df.columns if c not in excl_columns])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM