Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
csv filtering with python.
#6
csv file:


import csv

def filter_csv(csv_file):
    reader = csv.DictReader(csv_file)
    return set((row['part_number'], row['product_serial_number']) for row in reader)


@upload_csv_blueprint.route('/upload_csv', methods=['GET','POST'])
@login_required
def upload_file():
    if request.method == 'POST':
        csvfile = request.files['file']
        for product in filter_csv(csv_file=csvfile):
            print(','.join(product))
tested with
with open('products.csv') as csvfile:
    for product in filter_csv(csv_file=csvfile):
        print(','.join(product))
Output:
04X-1101-0116,1633-0001 04X-1101-0114,1633-0002 04X-1101-0112,1633-0021 04X-1101-0113,1633-0050 04X-1101-0115,1633-0020

by the way, 'excel' is just name of one of the available dialects in csv module. I didn't think it's excel file
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

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 762 Nov-15-2023, 06:54 PM
Last Post: deanhystad
  Help with filtering in Python Junes786 2 96,008 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