title: Python Loop to Create Dictionary
body: <p>I need to create lookup tables in python from a csv.  I have to do this, though, by unique values in my columns. The example is attached.  I have a <code>name</code> column that is the name of the model.  For reach model, I need a dictionary with the title from the <code>variable</code> column, the key from the <code>level</code> column and value from the <code>value</code> column. I'm thinking the best thing is a dictionary of dictionaries.  I will use this look up table in the future to multiply the values together based on the keys. </p>
  
  <p>Here is code to generate sample data set:</p>
  
  <pre><code> Name = ['model1', 'model1', 'model1', 'model2', 'model2', 
  'model2','model1', 'model1', 'model1', 'model1', 'model2', 'model2', 
  'model2','model2']
   Variable = ['channel_model','channel_model','channel_model','channel_model','channel_model','channel_model', 'driver_age', 'driver_age', 'driver_age', 'driver_age', 
  'driver_age', 'driver_age', 'driver_age', 'driver_age']
  channel_Level = ['Dir', 'IA', 'EA','Dir', 'IA', 'EA', '21','22','23','24', '21','22','23','24']
  Value = [1.11,1.18,1.002, 2.2, 2.5, 2.56, 1.1,1.2,1.3,1.4,2.1,2.2,2.3,2.4]
  df= {'Name': Name, 'Variable': Variable, 'Level': channel_Level, 'Value':Value}
  factor_table = pd.DataFrame(df)
  </code></pre>
  
  <p>I have read the following but it hasn't yielded great results:
   <a href="https://stackoverflow.com/questions/14196013/python-creating-dictionary-from-excel-data">Python Creating Dictionary from excel data</a></p>
  
  <p>I've also tried:</p>
  
  <pre><code>import pandas as pd
  factor_table = pd.read_excel('...\\factor_table_example.xlsx')
  
  #define function to be used multiple times
  def factor_tables(file, model_column, variable_column, level_column, value_column):
      for i in file[model_column]:
          for row in file[variable_column]:
              lookup = {}
              lookup = dict(zip(file[level_column], file[value,column]))
  </code></pre>
  
  <p>This yields the error:
  `dict expected at most 1 arguments, got 2</p>
  
  <p>What I would ultimately like is:
  <code>{{'model2':{'channel':{'EA':1.002, 'IA': 1.18, 'DIR': 1.11}}}, {'model1'::{'channel':{'EA':1.86, 'IA': 1.66, 'DIR': 1.64}}}}</code></p>