how to drop every ood column in python

Assuming that the columns in your dataframe (let's call it df) are indexed starting at 0, you can use the modulo operator (%) in combination with a list comprehension to remove all the odd columns like this:

main.py
df = df[[col for i, col in enumerate(df.columns) if i % 2 == 0]]
65 chars
2 lines

This will create a new dataframe containing only the even columns of the original df.

related categories

gistlibby LogSnag