title: Creating data frames from a groupby data frame
body: <p>I have this <a href="https://i.stack.imgur.com/ea1w8.png" rel="nofollow noreferrer">DataFrame</a> containing stock data and I want to iterate over it to create one df for each ticker (ex. PETR4.SA). I've done it manually with <code>groupby</code> and <code>.get_group</code>, but I don't know how to do it with <code>for</code> or <code>def</code>. The code right now is:</p>
  
  <pre><code>import pandas as pd
  import yfinance as yf
  import pandas_datareader.data as pdr
  
  yf.pdr_override()
  tickers = ['PETR4.SA', 'FLRY3.SA', 'ODPV3.SA', 'CREM3.SA', 'BPHA3.SA']
  acoes = pdr.get_data_yahoo(tickers) 
  
  # This line until the end  is to transform the multiindex of tickers into a column
  acoes.index.name = 'date'  
  long_form = acoes.reset_index().melt('date', var_name=['var','ticker'])  
  df = long_form.pivot_table(index=['date', 'ticker'], columns='var', values='value').reset_index()
  
  # Grouping the df by tickers
  grupos = DF.groupby('ticker')
  grupos.groups # The groups are presented in dicts, don't know if this helps or not
  </code></pre>