I am trying to filter a dataframe which has up to 100 columns. The first 3 columns are string values and the rest are numerical.
I need to filter for negative values in any of the columns defined within a list (which is dynamic depending on the last working day of the month.
I create a list of the column names I need to filter on based on Month End using:
my_list = ["S+" + str(i) for i in range(0, (int(s_int_value)+1))]
I now wish to use this list to filter on all rows which include negative values in any of those columns.
So far I have tried to use the following:
df = df[(df[my_list] < 0)]
However the dataframe only returns the negative values in the dataframe and everything else is set to ‘nan’
I need something similar to my old query:
df[(df['S+0'] < 0) | (df['S+1'] < 0) | (df['S+2'] < 0) | (df['S+3'] < 0)]
Which filtered all rows on negative values and left the remaining cells values as they were!
Thanks!