I'm trying to remove columns that have 0 in the 2nd row of the following dataframe snippet(there are many more columns than this however):
1st Year Gender CDK6 1st Year Gender GBP1 1st Year Gender LY9 Future All CCDC144B
0 1 1 1 0
1 0 1 0 1
I simply need to remove the columns where the 2nd row has a 0 in it. The result will be:
1st Year Gender GBP1 Future All CCDC144B
0 1 0
1 1 1
I have code here that gets the column names and then I attempt to drop them, however I am getting a key error.
drop_columns = []
for x in percent_scoring:
if percent_scoring[x][1] == 0:
drop_columns.append(x)
for x in drop_columns:
percent_scoring = percent_scoring.drop(columns=x)
but I get an unexpected key error
KeyError: "['1st Year All CDK6', '1st Year Gender CDK6', '1st Year Gender LY9'] not in index"
Not sure why the key error, but an easy way to do this would be appreciated. I couldn't find any info on this task which seems to be simple. Thanks