I am trying to format the data in input.csv
so that it returns the indexes that satisfies the conditions of Indexes
. I want the code to print out all the indexes of rows that have all the values defined in the #intervals
. Only the first row of element [ 2. 2. 30.]
satisfies for the limits defined at the Indexes
variables. Essentially I want to print out all the rows: Thats satisfy the condition: if column['MxU'] >= MxU and column['SNPT'] >= SNPT..... and column['MxD'] >= MxD
input.csv file:
element,LNPT,SNPT,NLP,NSP,TNT,TPnL,MxPnL,MnPnL,MxU,MxD
[ 2. 2. 30.],0,0,4,4,8,-0.1,-0.0,-0.1,17127,-3
[ 2. 2. 40.],0,0,2,2,4,0.0,-0.0,-0.0,17141,-3
[ 2. 2. 50.],0,0,2,2,4,0.0,-0.0,-0.0,17139,-3
[ 2. 2. 60.],2,0,6,6,12,0.5,2.3,-1.9,17015,-3
[ 2. 2. 70.],1,0,4,4,8,0.3,0.3,-0.0,17011,-3
Code:
df = pd.read_csv('input.csv')
#intervals
MxU= 17100
SNPT= 1
NLP= 3
MnPnL= -0.1
MxD= 0
#variables used for formatting
Indexes = [MxU,SNPT,NLP,MnPnL,MxD]
#all columns in csv listed
columns = ['LNPT', 'SNPT', 'NLP', 'MxPnL', 'NSP', 'TNT', 'TPnL', 'MnPnL','MxU','MxD']
def intersect() :#function for
for i in columns:
if str(Indexes[i]) in columns[i]:
for k in Indexes:
formating = df[columns] >= Indexes[k]
intersect() #calling function
Expected Output:
row: 1 element:[ 2. 2. 30.]