title: groupby and join with pandas dataframe
body: <p>Here is part of the data of scaffold_table
  <a href="https://i.stack.imgur.com/uLcHO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uLcHO.png" alt="enter image description here" /></a></p>
  <pre><code>import pandas as pd
  scaffold_table = pd.DataFrame({
  'Position':[2000]*5, 
  'Company':['Amazon', 'Amazon', 'Alphabet', 'Amazon', 'Alphabet'], 
  'Date':['2020-05-26','2020-05-27','2020-05-27','2020-05-28','2020-05-28'],
  'Ticker':['AMZN','AMZN','GOOG','AMZN','GOOG'],
  'Open':[2458.,2404.9899,1417.25,2384.330078,1396.859985],
  'Volume':[3568200,5056900,1685800,3190200,1692200],
  'Daily Return':[-0.006164,-0.004736,0.000579,-0.003854,-0.000783],
  'Daily PnL':[-12.327054,-9.472236,1.157283,-7.708126,-1.565741],
  'Cumulative PnL/Ticker':[-12.327054,-21.799290,1.157283,-29.507417,-0.408459]})
  </code></pre>
  <p>I would like to create a summary table that returns the overall yield per ticker. The overall yield should be calculated as the total PnL per ticker divided by the last date's position per ticker</p>
  <pre><code># Create a summary table of your average daily PnL, total PnL, and overall yield per ticker
  summary_table = pd.DataFrame(scaffold_table.groupby(['Date','Ticker'])['Daily PnL'].mean())
  
  position_ticker = pd.DataFrame(scaffold_table.groupby(['Date','Ticker'])['Position'].sum())
  
  # the total PnL is the sum of PnL per Ticker after two years period
  totals = summary_table.droplevel('Date').groupby('Ticker').sum().rename(columns={'Daily PnL':'total PnL'})
  
  summary_table = summary_table.join(totals, on='Ticker')
  summary_table = summary_table.join(position_ticker, on = ['Date','Ticker'], how='inner')
  summary_table['Yield'] = summary_table.loc['2022-04-29']['total PnL']/summary_table.loc['2022-04-29']['Position']
  summary_table
  </code></pre>
  <p>But the yield is showing NaN, could anyone take a look at my codes?
  I used ['2022-04-29'] because it is the last date, but I think there are some codes to return the last date without explicitly inputting that.
  <a href="https://i.stack.imgur.com/yawzf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yawzf.png" alt="enter image description here" /></a></p>