In order to drop a list of columns from a dataframe in python, you can simply use the .drop()
method and pass in the list of columns to drop. Here's an example:
main.py284 chars14 lines
Output:
main.py20 chars5 lines
In the code above, we create a sample dataframe with columns 'a', 'b', and 'c'. We then create a list of columns we want to drop, which is ['b', 'c']
. Then we simply use the .drop()
method to drop the columns specified in the list. The axis=1
parameter indicates that we want to drop columns, not rows. Finally, we print the new dataframe with only column 'a'.
gistlibby LogSnag