To delete a column in a pandas DataFrame in Python, you can use the drop method with the axis parameter set to 1. Here's an example:
main.py268 chars12 lines
Output:
main.py67 chars5 lines
In the code above, we first create a sample DataFrame df with three columns (name, age, and gender). We then drop the gender column using the drop method with axis=1. Finally, we print the resulting DataFrame to verify that the column was indeed deleted.
gistlibby LogSnag