df.sort_values(by='YTDchange', inplace=True) output = [] for index in range(10): company = df.iloc[[index]] est = estimates.get_stock_estimates(company['Symbol'].values[0]) recs = est['recommendations'][0] targets = est['price_target'] row = [ company['Symbol'].values[0], company['Company'].values[0], company['Price'].values[0], company['YTDchange'].values[0], recs['strongBuy'] + recs['buy'], recs['hold'], recs['sell'] + recs['strongSell'], targets['targetHigh'], targets['targetMean'], targets['targetLow'], targets['lastUpdated'], ] output.append(row) tt.print(output, header=[ 'Symbol', 'Company', 'Price', 'YTDchange', 'Buy', 'Hold', 'Sell', 'Target High', 'Target Mean', 'Target Low', 'Last Updated' ])