Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8737159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:27:12+00:00 2026-06-13T10:27:12+00:00

We basically have a large xcel file and what im trying to do is

  • 0

We basically have a large xcel file and what im trying to do is create a list that has the maximum and minimum values of each column. there are 13 columns which is why the while loop should stop once it hits 14. the problem is once the counter is increased it does not seem to iterate through the for loop once. Or more explicitly,the while loop only goes through the for loop once yet it does seem to loop in that it increases the counter by 1 and stops at 14. it should be noted that the rows in the input file are strings of numbers which is why I convert them to tuples and than check to see if the value in the given position is greater than the column_max or smaller than the column_min. if so I reassign either column_max or column_min.Once this is completed the column_max and column_min are appended to a list( l ) andthe counter,(position), is increased to repeat the next column. Any help will be appreciated.

input_file = open('names.csv','r')
l= []  
column_max = 0
column_min = 0
counter = 0
while counter<14:
    for row in input_file:
        row = row.strip()
        row = row.split(',')
        row = tuple(row)
        if (float(row[counter]))>column_max:
            column_max = float(row[counter])  
        elif (float(row[counter]))<column_min:
            column_min = float(row[counter])    
        else:
            column_min=column_min
            column_max = column_max
    l.append((column_max,column_min))
    counter = counter + 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:27:14+00:00Added an answer on June 13, 2026 at 10:27 am

    Once you have consumed the file, it has been consumed. Thus iterating over it again won’t produce anything.

    >>> for row in input_file:
    ...     print row
    1,2,3,...
    4,5,6,...
    etc.
    >>> for row in input_file:
    ...     print row
    >>> # Nothing gets printed, the file is consumed
    

    That is the reason why your code is not working.

    You then have three main approaches:

    1. Read the file each time (inefficient in I/O operations);
    2. Load it into a list (inefficient for large files, as it stores the whole file in memory);
    3. Rework the logic to operate line by line (quite feasible and efficient, though not as brief in code as loading it all into a two-dimensional structure and transposing it and using min and max may be).

    Here is my technique for the third approach:

    maxima = [float('-inf')] * 13
    minima = [float('inf')] * 13
    with open('names.csv') as input_file:
        for row in input_file:
            for col, value in row.split(','):
                value = float(value)
                maxima[col] = max(maxima[col], value)
                minima[col] = min(minima[col], value)
    
    # This gets the value you called ``l``
    combined_max_and_min = zip(maxima, minima)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, basically, I have a large list of phone numbers in a text file
I have rather large project that uses ICU regex classes. Basically it might run
I basically have a program that filters records from one excel file to another
Basically, I have a large number of C structs to keep track of, that
I have a large auditing stored procedure that prints values and runs some SELECT
I have a large static list which is basically a lookup table, so I
I have a large number of stored procedures that basically do the same thing:
Basically I have a bunch of large strings that I want to remove spaces/punctuation/numbers
I need some help. Basically, I have a large dataset that I have split
I basically have a fixed width DIV with an unordered list inside that overflows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.