If you are searching for keywords like Total
, explicitly in column names, use the following:
For this dummy data:
Description,Qty,Unit Cost (AED), Total Cost (AED), Amount (xyz)
string 1, 3, 3000, 9000, 9500
string 1, 3, 3000, 9000, 9500
string 1, 3, 3000, 9000, 9500
string 1, 3, 3000, 9000, 9500
string 1, 3, 3000, 9000, 9500
string 1, 3, 3000, 9000, 9500
Try the following code:
import pandas as pd
import re
df = pd.read_csv('test.csv')
print(df)
col = [name for name in df.columns if len(re.findall(r'\b(?:total|amount)\b', name.lower()))!=0]
if len(col)!=0:
print(df.loc[:, col])