Cloud Stack Ninja

I have the following df:

                                  0      1      2           3          4
3                 Services rendered                       HK$’000 HK$’000
5  Audit and audit related services                          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] and df[4] is the column in interested, not df[1] or df[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.

Read more here:

Content Attribution

This content was originally published by chris_2020 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: