Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- columns_to_retain = 'name, sex, age' # a string of columns
- # which will not be dropped
- # from the dataframe
- x_cols = columns_to_retain.split(',')
- new_df = df.drop(columns = not x_cols)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement