Let's say you have following content in csv file
Col1,Col2, Col3
1,a,0
2,b,0
3,d,1
Read it in pandas dataframe using following script
import pandas as pd
df=pd.read_csv(file)
To see the columns in dataframe df use
print(df.columns)
This will give you the column names in df in form of list, in this case ['col1', 'col2', 'col3']
To retain only specific columns (for example col1 and col3) you can use
df=df [ [ "col1","col3"] ]
Now if you print (df.columns) it will only have ['col1', 'col3']
Edited in reply to the comment:
If you want to delete the columns that fulfil certain condition you can use the following script
for column in df.columns:
if 0 in df[column].values: # This will check if 0 is in values of column, you can add any condition you want here
print('Deleting column', column) # I assume you want to delete the column that fulfills the condition
df=df.drop(columns=column) # This statement will delete the column fulfilling the condition
print("df after deleting columns:")
print(df)
It will print
Deleting column col3
df after deleting columns:
col1, col2
1,a
2,b
3,c