This question touches upon the problem that I am facing. However, instead of excluding columns based on an exact string match, I want to exclude columns if a particular substring matches.
For example, in the image below, I would like to filter out columns A and C because they contain the substring 'is'
How would I go on about doing this? I replaced df.loc[:, ~(df == 'Salty').any()]
from @cs95's answer to df.loc[:, ~(re.findall('/\w+(?:is)\w+/', df)).any()]
but this gives me a
TypeError: expected string or bytes-like object
Any help would be appreciated!
Input
|---------------------|------------------|----------------|----------|
| | A | B | C |
|---------------------|------------------|----------------|----------|
| Value | Red | Green |Blue |
|---------------------|------------------|----------------|----------|
| 12 | HotisGood | Warm |isGood |
|---------------------|------------------|----------------|----------|
Output
|---------------------|--------------|
| | B |
|---------------------|--------------|
| Value | Green |
|---------------------|--------------|
| 12 | Warm |
|---------------------|--------------|