Searching for element in a column by iterating over the column, pandas
Searching for element in a column by iterating over the column, pandas In my data frame I need to remove columns that contain a specific character. In order to search for those columns, I am trying to write a for loop in python that iterate over each column and, if find a column with the unwanted character, this column has to be dropped out. My data frame appears like this and I need to drop col3 and col5 that have 'f' and 't' col1 col2 col3 col4 col5 col6 1245 pink f Mar f f 245 green f Feb t f 1237 grey t Apr f f 267 black f Sep t f I am trying to write a script similar to this for col in df.items(): if df[col] == 'f' df = df.drop([col], axis=1) Does the column 6 have to stay? – Joe 1 min ago 2 Answers ...