title: Create simple logic rules (and,or) from pandaframe
body: <p>I would like to take values from a CSV document and create rules based on the values taken. The question is probably more in the direction of statistics, but I would like to know how I can create parameters for the bounds to achieve a desired score, if it is possible . I distinguish the values of the document with the parameter 'quality'. How do I maximize parameters so I can achieve an optimum rating? How do I apply the created rules to the panda frame as simply as possible? I ignore the tag parameter .</p>
  <p>Die ist so strukturiert:</p>
  <pre><code>image_name,level,count,detail_entropy,color_der,ssum,ssum2,hs,hb,hg,obj,sat,hue,gamma,sb,sg,sr,sx,sy,smin,smax,sk,noise_lv,avvp,blur_value,tag1,tag2,tag3,tag4,tag5,quality
  wallpaper1,0.01720315866276719,2,3.6346517386525146,44.309189953623786,-5461729.0,91354.0,392293,392293,392293,161,26.25432916666667,19.5854375,1.6793419856653888,9.0,6.0,3.0,0.0,-0.12914445,-4367.0,4256.0,2.869797621119288,2.141462205621831,17.937872916666667,1769.7631112435377,jellyfish,switch,envelope,sea_cucumber,traffic_light,1
  wallpaper2,0.2378536927802515,4,8.913238003699101,73.03964357110003,128894130.0,-56188.0,43360,43360,43360,172,80.06717291666666,85.7450125,1.08356949882904,0.0,0.0,0.0,-0.5805972,0.49715278,-2757.0,2764.0,0.3243596159730514,2.4037708817108525,87.72517916666666,1367.5927782420792,cowboy_boot,cloak,horizontal_bar,ski_mask,sarong,1
  wallpaper3,0.23403080955980254,4,9.065773348462493,55.31522810752534,11064554.0,-230740.0,10016,10016,10016,525,102.70878541666667,44.50304375,1.028384771213943,-21.0,-33.0,-31.0,0.11145417,0.027744444,-3364.0,3608.0,0.616648338704692,2.7680159704038076,111.53093333333334,1560.8406504145664,whippet,Boston_bull,French_bulldog,bustard,Cardigan,0
  
  </code></pre>
  <p>Code:</p>
  <pre><code># -*- coding: utf-8 -*-
  from __future__ import print_function
  from __future__ import division
  import numpy as np
  import pandas as pd
  import os,sys
  
  # flags  !!
  pandaframe = 0
  pandaframe_var_name = &quot;&quot;
  #&quot;a_series&quot;
      
  file = sys.argv[1]
  df = pd.read_csv(file)
  
  
  condition_and = &quot;&quot;&quot; and &quot;&quot;&quot;
  condition_or  = &quot;&quot;&quot; or &quot;&quot;&quot;
  greater = &quot;&quot;&quot;&gt;=&quot;&quot;&quot;
  smaller = &quot;&quot;&quot;&lt;=&quot;&quot;&quot;
  
  
  def sortSecond(val):
      return val[2] 
  
  def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):
      return abs(a-b) &lt;= max(rel_tol * max(abs(a), abs(b)), abs_tol)
      
      
  def check_counter(df,entry,min=-sys.maxsize-1,max=sys.maxsize):
      fit_values = df[(df[entry] &lt;= max) &amp; (df[entry] &gt;= min)]
      return len(fit_values)
      
  header_names = list(df.columns.values[1:-6])
  
  threshold_corr = 0.10
  highest_corr = 0
  list_all = []
  for idx, word in enumerate(header_names):
      if('quality' in word):
          continue
      correlation = df[word].corr(df['quality'])
      if(correlation&lt;0):
          vorzeichen = &quot;-&quot;
      else:
          vorzeichen = &quot;+&quot;
      entry = [word,vorzeichen,abs(correlation), df[word].mean(),df[word].min(),df[word].max()]
      list_all.append(entry)
      if(abs(correlation)&gt;=highest_corr):
          highest_corr = correlation
          hname = word
  
  dfn= df[df['quality'] != 0]
  df_true= df[df['quality'] != 1]
  for x in list_all:
      word_to_mean = x[0]
      x[3] = dfn[word_to_mean].mean()
      x[4] = dfn[word_to_mean].min()
      x[5] = dfn[word_to_mean].max()  
          
  
  list_all.sort(key = sortSecond, reverse = True)
  list_all = list_all[:9]
  
  final_string = &quot; &quot;
  counter = 1
  length = len(list_all)
  
  for i,x in enumerate(list_all):
      if(pandaframe_var_name!=&quot;&quot;):
          cache = x[0]
          x[0] = str(pandaframe_var_name) + &quot;&quot;&quot;['&quot;&quot;&quot; + str(cache) + &quot;&quot;&quot;']&quot;&quot;&quot;
      std_max = x[3]*(1.4+0.5*i)
      std_max_min = x[3]*(0.7-0.075*i)
      if(std_max_min&gt;std_max):
          cache = std_max
          std_max = std_max_min
          std_max_min = cache         
      if(std_max&gt;x[5]):
          std_max = x[5]
      if(std_max_min&lt;x[4]):
          std_max_min = x[4]  
      #assert( std_max_min&gt;=std_max)
      if((i+1)!=length):
          if(&quot;+&quot; in x[1]):
              # variabel[x[0]] &gt;= min[x[4]] and variabel &lt;=max[x[5]]
              final_string = final_string + x[0] + str(greater) + str(std_max_min) + str(condition_and) + str(x[0]) + str(smaller) + str(std_max) + str(condition_and)
          else:
              final_string = final_string + str(x[0]) + str(smaller) + str(std_max) + str(condition_and)  
      else:
          if(&quot;+&quot; in x[1]):
              # variabel[x[0]] &gt;= min[[]] and variabel &gt;=max[x[5]]
              final_string = final_string + x[0] + str(greater) + str(std_max_min) + str(condition_and) + str(x[0]) + str(smaller) + str(std_max) 
          else:
              final_string = final_string + str(x[0]) + str(smaller) + str(std_max)   
  
  
  print(final_string)
  </code></pre>