I have a dataframe:
Product | Storage | Price | |
---|---|---|---|
Azure | (2.4% | Server | £540 |
AWS | Server | £640 | |
GCP | Server | £540 |
I would like to remove the column which contains the string '(2.4%' however I only want to remove the column in Pandas through regex if regex finds either a bracket or percentage in the string in that column '(%' and then pandas should drop that column entirely.
Please can you help me find a way to use regex to search for special characters within a string and drop the column if that condition is met?
I've searched on stack/google. I've used the following so far:
df = df.drop([col for col in df.columns if df[col].eq('(%').any()], axis=1)
chars = '(%'
regex = f'[{"".join(map(re.escape, chars))}]'
df = df.loc[:, ~df.apply(lambda c: c.str.contains(regex).any())]
however neither of these worked.
Any help would be greatly appreciated. :)
Thank You * Insert Smiley*