I have a csv file I'm importing as a list
[["df['EPS Rating']>=97"],
["df['RS Rating']>=97"],
["df['Ind Group RS']<=9"],
["df['SMR Rating']<=2"],
["df['AD Rating']<=9"],
["df['Comp Rating']>=85"],
["df['Current Price']>=15"]]
I would like to assign each of these to variables c1 to c7 like this
c1 = df['EPS Rating']>=97
c2 = df['RS Rating']>=97
c3 = df['Ind Group RS']<=9
c4 = df['SMR Rating']<=2
c5 = df['AD Rating']<=9
c6 = df['Comp Rating']>=85
c7 = df['Current Price']>=15
This is so I can use this excellent solution I found by Gecko here also shown below. While this solution is great for readability in my case it ends up being huge as I have more than 30 of these filters and many with more than 20 conditions. How can I assign strings in a list to variables?
something like this maybe?
For i to end_of_list:
c[i] = [i].value
I hope that explains what I'm trying to do. I'm new to python so I'm still a bit lost. I'm not attached to this idea so if anyone has a better solution I'd love to know it. Thanks
Geckos Original Solution:
import numpy as np
import functools
def conjunction(*conditions):
return functools.reduce(np.logical_and, conditions)
c_1 = data.col1 == True
c_2 = data.col2 < 64
c_3 = data.col3 != 4
data_filtered = data[conjunction(c1,c2,c3)]