title: Condition for certain values in a for loop (Python pandas)
body: <p>I have a dataframe of stock returns for several companies on the S&amp;P. I have caluclate their returns.</p>
  
  <p>I want to have a for loop which gets the top 5 (for instance) companies with the highest return values (on average over the period) and lowest 5 companies return values from a large dataframe. Then I want to plot it.</p>
  
  <p>I have a code which gives me all the companies' returns and plots them.</p>
  
  <pre><code>graph_df = pd.DataFrame()
  
  for name in df['Name'].unique():
      print(name) # keeping track of which tickers are included
      name_df = df.copy()[df['Name']==name] # creating a new df, copying in the name columns
      name_df[f"{name}_factor"] = name_df["Difference"]
      if graph_df.empty:
          graph_df = name_df[[f"{name}_factor"]]
      else:
          graph_df = graph_df.join(name_df[f"{name}_factor"])
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/UmEqx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UmEqx.jpg" alt="Plot"></a></p>
  
  <p>This is a snippet from print(graph_df):</p>
  
  <pre><code>             StockRet1   StockRet2   StockRet3   StockRet4   StockRet5
  Dates                                                                  
  1990-01-31   0.000000    0.000000    0.000000    0.000000    0.000000  
  1990-02-28  -0.098820    0.000000   -0.076981    0.019755   -0.012170  
  1990-03-30   0.023653    0.000000   -0.011115    0.044565   -0.042621  
  1990-04-30   0.010303    0.000000   -0.074512    0.067319   -0.003569  
  </code></pre>
  
  <p>The plot is very messy as you can see, so I want to only show the highest and the lowest. I appreciate all help! </p>