title: how to create a dictionary of pandas dataframes, and return the dataframes into excel worksheets?
body: <p>how to create a dictionary of pandas dataframes, and return the dataframes into excel worksheets?</p>
  
  <p>Hi All,</p>
  
  <p>I am learning pandas and python, and I want to create a dictionary which contains a some dataframes, which I can then run metrics over each dataframe. With each unique cluster name (one of the columns) I would like to create a dataframe (subset of original dataframe.</p>
  
  <p>Then I would like to be able to select it, run metrics over it, putting the results in a new dataframe, and then place the original dataframe (each subset) into a separate worksheet using xlsxwriter python library.</p>
  
  <pre><code>#create dictionary object
  
      c_dict = {}
  
  #get a list of the unique names
  
  c_dict= data.groupby('Cluster').groups
  
  #create a dictionary of dataframes, one for each cluster
  
  for cluster in c_dict.items():
      df = data[data['Cluster']==cluster
      c_dict[cluster] =df                                                        &lt;&lt;&lt; im getting invalid syntax here
  
  #go through the dictionary and create a worksheet and put the dataframe in it.
  
  for k,v in c_dict.items():
      dataframe = GetDF(k)                                                            &lt;&lt;&lt; creating worksheets and puts the data from the dataframe &gt; worksheet is not working because of invalid syntax when trying to create dataframe dictionary ^^
      dataframe.to_excel(writer,sheet_name=k)
  writer.save
  
  #get the dataframe from the dictionary,
  
  GetDF(dictionary_key)
            return c_dict[dictionary_key]
  </code></pre>