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
#4
this might work too, but it doesn't give an output:

import argparse
f = open(csvinput)

for line in f:
    if "Medal" not in line:
        data = line.split(",")
        name = data[0]
        event = data[1]
        year = data[2]
        country = data[3]
        print("Name: " + name + "\tEvent: " + event + "\tYear: " + year + "\tCountry: " + country)

print("Please provide a year:")
year = input()
print("Please provide a country:")
country = input()

for line in f:
    data = line.split(",")
    if data[2] == year and data[3] == country:
        name = data[0]
        event = data[1]
        year = data[2]
        country = data[3]
        print("Name: " + name + "\tEvent: " + event + "\tYear: " + year + "\tCountry: " + country)
Reply


Messages In This Thread
RE: Sorting data by specific variables using argparse - by Bearinabox - Dec-31-2022, 07:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Data Sorting and filtering(From an Excel File) PY_ALM 0 1,171 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,557 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,359 Jul-27-2018, 02:07 PM
Last Post: nrozman
  How to filter specific rows from large data file Ariane 7 8,467 Jun-29-2018, 02:43 PM
Last Post: gontajones
  Plotting climate data with NetCdf files for a specific region with coordinates fyec 3 5,606 Jun-27-2018, 12:34 PM
Last Post: buran
  A small data sorting program - couple of general and hopefully easy questions Ansifatcat 2 3,042 Jan-25-2018, 05:29 AM
Last Post: Ansifatcat
  Replacing values for specific columns in Panda data structure Padowan 1 14,780 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