Q:

How can I loop through an index and keep the associated row information?

I have a loop within my function that is supposed to find the max rate, min rate, and compute the average, and the function that I wrote is doing this right, but how can I keep the row information when I find the max, and min within my data? I'm a beginner at python, but here is the loop that I have. 
    max_rate = -1 
    min_rate = 25 
    count = 0 
    sum = 0
    with open(file_names, "r") as file_out:
   # skips the headers in the file
      next(file_out)
      for line in file_out: 
         values = line.split(",")
 # since rate is index 6 that is what we are going to compare to values above
        if float(values[6]) > max_rate: 
           max_rate = float(values[6])
        if float(values[6]) < min_rate:
           min_rate = float(values[6])
     count += 1
  # sum up all rates in the rates column
     sum = float(values[6]) + sum 
     avg_rate = sum / count
     print(avg_rate)

I have printed the average just to test my function. Hopefully the question I am asking makes sense, I don't just want the 6th index but I want the rest of the row information that has the min or the max. An example would be to get the company name, state, zip, and rate.  Don't worry about indentations, I don't know if I formatted it right in the code block here, but all the indents are right in my code chunk. 

A:

It looks like you're working with CSV or other table-like data. Pandas handles this really well. An example would be:
import pandas as pd

df = pd.read_csv('something.csv')
print(df)

print(f'\nMax Rate: {df.rate.max()}')
print(f'Avg Rate: {df.rate.mean()}')
print(f'Min Rate: {df.rate.min()}')
print(f'Last Company (Alphabetically): {df.company_name.max()}')

Yields:
    company_name         state    zip    rate
0  Company1 Inc.         Texas  76189  0.6527
1  Company2 LLC.  Pennsylvania  18657  0.7265
2  Company3 Corp       Indiana  47935  0.5267

Max Rate: 0.7265
Avg Rate: 0.6353
Min Rate: 0.5267
Last Company (Alphabetically): Company3 Corp

