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
#3
Thanks for replying - I'm really new at this.
sample data:

Name Team Year Event Medal
Christian Mayer Austria 1998 Alpine Skiing Men's Combined Bronze
Mario Reiter Austria 1998 Alpine Skiing Men's Combined Gold
Josef Polig Italy 1992 Alpine Skiing Men's Combined Gold
Harald Christian Strand Nilsen Norway 1994 Alpine Skiing Men's Combined Bronze


what I've done so far - here, I'm also trying to filter by year and/or country, and then I get the error; I'm certain I'm missing something obvious.

import argparse
from argparse import ArgumentParser

parser = argparse.ArgumentParser()
parser.add_argument('-f')
parser.add_argument('-y', action='store_true')
parser.add_argument('-c', action='store_true')
args = parser.parse_args()


# Select include year and country from arguments
selection = input('Please input year and/or country:')
usecols = selection([])
if args.y: usecols.append('Year')
if args.c: usecols.append('Country')

# Read the file in the f argument with the specified columns.
year_country = december_project(args.f, usecols=usecols)
Reply


Messages In This Thread
RE: Sorting data by specific variables using argparse - by Bearinabox - Dec-31-2022, 07:31 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