title: Return pandas groupby based on input
body: <p>I'm trying to display different DataFrames based on user input.</p>
  
  <p>I have created a script requesting for user input: 
  <code>myscript.py</code></p>
  
  <pre><code>import libs.mssql as mssql
  
  db = mssql.Database()
  
  table_name = input("Please key in A, B or C: ")
  
  table = db.WAP(table_name)
  print(table)
  
  input("Press Enter to exit.")
  </code></pre>
  
  <p>The script should print out an output based on the class function below:</p>
  
  <pre><code>class Database():
      def __init__(self):
          self.cnxn = pyodbc.connect(cnxn details)
  
      def WAP(self, table_name):
          sql = "EXECUTE Contract_Balance"
          df = pd.read_sql(sql, self.cnxn)
  
          A_filter = (df.Table_Name == 'A')
          B_filter = (df.Table_Name == 'B') &amp; (df.Product != 'C')
          C_filter = (df.Table_Name == 'C') &amp; (df.Product == 'C')
  
          # Copy from df based on filters
  
          A = df[A_filter].copy()
          B = df[B_filter].copy()
          C = df[C_filter].copy()
  
          myDict = {"A": A, "B": B, "C": C} 
  
          if table_name in ('A', 'C'):
              table = myDict[table_name]
              group = ['Delivery', 'Product']
  
          elif table_name == 'B':
              table = myDict[table_name]
              group = ['Delivery', 'Region']
  
          return np.round(
              table.groupby(group).\
              apply(lambda x: pd.Series([np.average(x.Product_Price, weights=x.Balance),x.Balance.sum()],index=['Product_Price', 'Balance'])).\
              unstack().\
              swaplevel(1,0,axis=1).\
              sort_index(axis=1).\
              replace(np.nan, 0) 
          , 2).replace(0, '')
  
  </code></pre>
  
  <p>The variables are <code>table</code> and <code>group</code>.</p>
  
  <p>Based on user input for the <code>table</code> (A, B or C), the variable <code>group</code> would change as well and affect the final output.</p>
  
  <p><code>myscript.py</code> fails with the error:
  <code>AttributeError: 'str' object has no attribute 'groupby'</code>, due to Python parsing the user input as a string, therefore the variables A, B and C (which have been defined in the class function <code>WAP</code>) are not returned.</p>
  
  <p>The expected result is that <code>myscript.py</code> prints out the correct table and group based on user input of <code>A</code>, <code>B</code> or <code>C</code></p>
  
  <p>Edit: Add a dictionary and looking it up with the function call solves this problem</p>