title: CSV: How to find name of the value from the list
body: <p>I have a code that reads CSV file which has 3 columns: Zone, Number, and ARPU and I try to write a recommendation system that finds the best match for each value of ARPU from the list provided in the code (creates column &quot;Suggested Plan&quot;). Also, it finds the next greater value (creates column &quot;Potential updated plan&quot;) and next lower value(&quot;Potential downgrade plan&quot;):</p>
  <pre><code>tp_usp15 = 1500
  tp_usp23 = 2300
  tp_usp27 = 2700
  
  list_usp = [tp_usp15,tp_usp23, tp_usp27]
  
  
  tp_bsnspls_s = 600
  tp_bsnspls_steel = 1300
  tp_bsnspls_chrome = 1800
  
  
  list_bsnspls = [tp_bsnspls_s,tp_bsnspls_steel,tp_bsnspls_chrome]
  
  tp_bsnsrshn10 = 1000
  tp_bsnsrshn15 = 1500
  tp_bsnsrshn20 = 2000
  
  list_bsnsrshn = [tp_bsnsrshn10,tp_bsnsrshn15,tp_bsnsrshn20]
  
  #Common list#
  common_list = list_usp + list_bsnspls + list_bsnsrshn
  
  
  import pandas as pd
  
  def get_plans(p):
      best = min(common_list, key=lambda x : abs(x - p['ARPU']))
      best_index = common_list.index(best)        # get location of best in common_list
      
      if best_index &lt; len(common_list) - 1:
          next_greater = common_list[best_index + 1]
      else:
          next_greater = best                     # already highest
  
      if best_index &gt; 0:
          next_lower = common_list[best_index - 1]
      else:
          next_lower = best                       # already lowest
  
      return best, next_greater, next_lower
  
  `common_list = list_usp + list_bsnspls + list_bsnsrshn
  common_list = sorted(common_list)   # ensure it is sorted
  df = pd.read_csv('root/test.csv')
  df[['Suggested plan', 'Potential updated plan', 'Potential downgraded plan']] = df.apply(get_plans, axis=1, result_type=&quot;expand&quot;)
  df.to_csv('Recommendation System.csv') `
  
  </code></pre>
  <p>It creates 3 additional columns and does the corresponding task (best match or closes value, next greater value, and next smaller value).The code works perfectly but as you can see each numeric value has its name</p>
  <p><em><strong>How to change the code to create additional columns with name next to new columns with numeric values?</strong></em></p>
  <p>For example, right now code produces:
  Zone, Number, ARPU, Suggested plan, Potential Updated Plan, and Potential downgrade plan</p>
  <p>!BUT! I need to create:</p>
  <p>Zone, Number, ARPU, Suggested plan (numeric), Suggested plan (name), Potential Updated Plan(numeric), Potential Updated Plan(name), Potential downgrade plan (numeric),Potential downgrade plan(name)</p>
  <p>Where columns with (name) will show the corresponding name to the value used in (numeric) columns. Thanks in advance, guys!</p>
  <p>Photo examples:
  Here is the starting CSV file.
  <a href="https://i.stack.imgur.com/neTLi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/neTLi.png" alt="enter image description here" /></a></p>
  <p>Then, after executing the code I have this:
  <a href="https://i.stack.imgur.com/uGs9n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uGs9n.png" alt="enter image description here" /></a></p>
  <p>And I want to create additional columns with corresponding names of valuables. Example columns in in yellow
  <a href="https://i.stack.imgur.com/dtUTr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dtUTr.png" alt="enter image description here" /></a></p>