I have the following df:
0 1 2 3 4
3 Services rendered 2000 HK$’000 HK$’000
5 Audit and audit related services 999 1,800 9,999
8 financial statements HK$’000 788 600 1,233,456
I want to capture columns which have both currency and financial number e.g. HK$’000 and 1,800 or 600.
- In this case,
df[3]anddf[4]is the column in interested, notdf[1]ordf[2]
The desire result is returning a DataFrame: df[[3, 4]] as the following
3 4
3 HK$’000 HK$’000
5 1,800 9,999
8 600 1,233,456
I tried
df_fin = df[df.apply(lambda x: x.str.contains('HK')) | df.apply(lambda x: x.str.contains('\d,?\d*'))]
df_fin.iloc[:, df_fin.any().to_list()]
but it captures df[1] and df[2] too. How may I have the desired result?
Thank you.