Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
csv filtering with python.
#1
I am attempting to take a csv file containing test results for products and filtering the results so that I know what product was tested and its serial number.

Each product has 5-10 tests run on it so i have to first eliminate all duplicates.

@upload_csv_blueprint.route('/upload_csv', methods=['GET','POST'])
@login_required
def upload_file():
    if request.method == 'POST':
        csvfile = request.files['file']
        s_n_bank = []
        main_bank = []
        p_n_bank = []
        reader = csv.DictReader(csvfile)

        for row in reader:
            temp_s_n=str(row['product_serial_number'])
            if temp_s_n not in s_n_bank:        # Filters the serial
                s_n_bank.append(temp_s_n)       # numbers so no 
                sorted_bank= s_n_bank.sort()    # duplicates. 
                single_entry= sorted_bank.pop() # Does not recognise .pop()

 # attempting to use the refined serial number list to extract the relevant part number. 
 #( UNTESTED ->)  
                for row in reader:
                    selected_entry= row.index(single_entry)    

                    temp_p_n = str(selected_entry['part_number'])
                    if temp_p_n not in p_n_bank:
                        p_n_bank.append(temp_p_n)
                        main_bank.append(p_n_bank)
                        main_bank.append(single_entry)
                        p_n_bank.remove(temp_p_n)

                        print main_bank
I have the error message - AttributeError: 'NoneType' object has no attribute 'pop'.
Any idea what my pop error is? Is the function obsolete ?
I am also aware that this is probably not the best way of conducting this search and am not certain that it will work ( as have not tested fully due to the pop error.) Any prompts on future errors i might find would be appreciated.
Reply


Messages In This Thread
csv filtering with python. - by KirkmanJ - Jun-26-2018, 09:48 AM
RE: csv filtering with python. - by buran - Jun-26-2018, 09:58 AM
RE: csv filtering with python. - by KirkmanJ - Jun-26-2018, 10:03 AM
RE: csv filtering with python. - by buran - Jun-26-2018, 10:08 AM
RE: csv filtering with python. - by KirkmanJ - Jun-26-2018, 10:11 AM
RE: csv filtering with python. - by buran - Jun-26-2018, 10:28 AM
RE: csv filtering with python. - by KirkmanJ - Jun-26-2018, 10:30 AM
RE: csv filtering with python. - by buran - Jun-26-2018, 10:44 AM
RE: csv filtering with python. - by KirkmanJ - Jun-26-2018, 10:47 AM
RE: csv filtering with python. - by buran - Jun-26-2018, 10:52 AM
RE: csv filtering with python. - by KirkmanJ - Jun-26-2018, 11:01 AM
RE: csv filtering with python. - by buran - Jun-26-2018, 11:13 AM
RE: csv filtering with python. - by KirkmanJ - Jun-26-2018, 11:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected Output - Python Dataframes: Filtering based on Overlapping Dates Xensor 5 712 Nov-15-2023, 06:54 PM
Last Post: deanhystad
  Help with filtering in Python Junes786 2 92,495 Jun-05-2019, 08:10 AM
Last Post: Junes786

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020