Python Forum
Sorting data by specific variables using argparse
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting data by specific variables using argparse
#6
I've been playing around with it, and I got it to work for the most part, except there's a problem. I can filter data by EITHER country or year, but not both. If I hash out one variable, it works, but I can't figure out how to combine it:

country = []
while True:
    value = str(input('To filter data, enter a country, type "done" when done: '))
    if value == 'done' :
        break
    try:
        value = str(value)
    except:
        print('Invalid input:')
        continue
    try:
        country.append(str(value))
    except:
        country.append(value)

print('you have entered: ',country)
print(type(country))

year = []
while True:
    value = input('Enter a year, type "done" when done: ')
    if value == 'done' :
        break
    try:
        value = int(value)
    except:
        print('Invalid input:')
        continue
    try:
        year.append(int(value))
    except:
        year.append(str(value))
print('you have entered:\n',year)


# filter out rows without year & country
olympics = name_country_year_event[name_country_year_event['Team'].isin(country) | name_country_year_event['Year'].isin(year)]

# print csv
print(olympics)
Any ideas?
Thanks!
Reply


Messages In This Thread
RE: Sorting data by specific variables using argparse - by Bearinabox - Jan-01-2023, 07:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Data Sorting and filtering(From an Excel File) PY_ALM 0 1,167 Jan-09-2023, 08:14 PM
Last Post: PY_ALM
  Training a model to identify specific SMS types and extract relevant data? lord_of_cinder 0 1,078 Oct-10-2022, 04:35 AM
Last Post: lord_of_cinder
Question Sorting data with pandas TheZaind 4 2,553 Nov-22-2021, 07:33 PM
Last Post: aserian
  Searching a .txt file for a specific number and extracting the corresponding data nrozman 3 3,354 Jul-27-2018, 02:07 PM
Last Post: nrozman
  How to filter specific rows from large data file Ariane 7 8,444 Jun-29-2018, 02:43 PM
Last Post: gontajones
  Plotting climate data with NetCdf files for a specific region with coordinates fyec 3 5,600 Jun-27-2018, 12:34 PM
Last Post: buran
  A small data sorting program - couple of general and hopefully easy questions Ansifatcat 2 3,040 Jan-25-2018, 05:29 AM
Last Post: Ansifatcat
  Replacing values for specific columns in Panda data structure Padowan 1 14,778 Nov-27-2017, 08:21 PM
Last Post: Padowan

Forum Jump:

User Panel Messages

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