title: Pandas: avoid using for loop in this example
body: <p>i have a dataframe below and a function below that takes a string as input and run <code>group by</code> the dataframe based on the string input. Right now, I am just using a loop to iterate over a list of strings to run the function one by one.</p>
  <p>My question is that how do I improve performance, make below more efficient and avoid using a for loop, as it is slow?</p>
  <p>I want to use <code>apply</code> and this would generate multiple dataframes but I do not how and how to store them into the dictionary structure that I use below.</p>
  <p><strong>Update: my actual function doesn't just do groupby, as it performs a lot of other operations after groupby. My actual dataframe also has a lot of other columns. For simplicity, I am not showing them here</strong></p>
  <p><code>df = pd.DataFrame({'y':[1,2,3,4,5,6,7,8,9,10],'key1':[1,1,2,2,3,3,4,4,5,5],'key2':[1,2,1,2,1,2,1,2,1,2],'key3':[1,1,1,1,1,2,2,2,2,2]})</code></p>
  <pre><code>def processing(df,grpId):
       df_res= df.groupby([grpId]).agg({'y':'sum'}) 
       return df_res
  
  df_dict = dict()
  for i in ['key1','key2','key3']:
          df_dict [i]= processing(df,grpId= i)
  </code></pre>