Python Forum
Filtering with IF Statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Filtering with IF Statement
#1
I am working on some Homework and the assignment call for us to open a CSV and pull the info out into columns with fixed widths. Afterwards we need to filter the info with after a user inputs a selection. and this is where I am stuck. I cant seem to get the list of states to filter after the user select. Any help would be great the assignment is due on Sunday and I have been working on it all week thanks to this forum and many other I am were I am now.

import csv

def Location(State): 
    State = state 
    if (State in state): 
        return True
    else: 
        return False

titleLocation = "Location"
titleDisease = "Disease"
titleNumber = "Number"
titleYear = "Year"
print("%-25s %-15s %-15s %-15s" %(titleLocation, titleDisease, titleNumber, titleYear))

total = 0
with open("health-no-head-sample.csv", "r") as health:
    file_reader = csv.reader(health)


    for aline in file_reader:
        total += float(aline[3])
        number = aline[3]
        state = aline[2]
        disease = aline[0]
        year = aline[5]
        print("%-25s %-15s %-15s %-15s" %(state, disease, number, year))
    print("%-25s %-15s %-15s" %('', 'Total', total))
State = input('Select a state ')
if State == state:
    filtered = filter(Location, state)
    for state in filtered:
        print(state)
Reply


Messages In This Thread
Filtering with IF Statement - by Mike2607 - Nov-28-2019, 09:40 PM
RE: Filtering with IF Statement - by Larz60+ - Nov-28-2019, 09:44 PM
RE: Filtering with IF Statement - by Mike2607 - Nov-28-2019, 10:09 PM
RE: Filtering with IF Statement - by Larz60+ - Nov-28-2019, 11:35 PM
RE: Filtering with IF Statement - by Mike2607 - Nov-29-2019, 01:31 AM
RE: Filtering with IF Statement - by Larz60+ - Nov-29-2019, 01:58 AM
RE: Filtering with IF Statement - by Mike2607 - Nov-29-2019, 02:05 AM
RE: Filtering with IF Statement - by Larz60+ - Nov-29-2019, 04:56 AM
RE: Filtering with IF Statement - by perfringo - Nov-29-2019, 08:20 AM
RE: Filtering with IF Statement - by Mike2607 - Nov-29-2019, 01:59 PM
RE: Filtering with IF Statement - by perfringo - Nov-29-2019, 07:18 PM

Forum Jump:

User Panel Messages

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