"""Count the penguins in each species. Run from a terminal: python3 penguin_count.py ../data/penguins.csv """ import argparse import pandas as pd def count_species(csv_path): """Read a CSV file and count each penguin species.""" df = pd.read_csv(csv_path) return df["species"].value_counts() def main(): # argparse reads the file path from the terminal command. parser = argparse.ArgumentParser(description="Count penguins per species") parser.add_argument("csvfile", help="path to the penguins CSV") args = parser.parse_args() print(count_species(args.csvfile).to_string()) # Run main() when we execute this file, but not when we import it. if __name__ == "__main__": main()