From 6ea3c54d50c2154ae73e07e5de70838efd3d11b1 Mon Sep 17 00:00:00 2001 From: Ashlyn Sloane Date: Mon, 31 Aug 2026 22:54:13 +0000 Subject: [PATCH 1/3] Implement get_column function --- .gitignore | 2 ++ my_utils.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8caa56f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Agrofood_co2_emission.csv +__pycache__/ diff --git a/my_utils.py b/my_utils.py index 923f010..2baa5f7 100644 --- a/my_utils.py +++ b/my_utils.py @@ -1,2 +1,9 @@ def get_column(file_name, query_column, query_value, result_column): - return None + result = [] + + with open(file_name, "r") as file: + for line in file: + values = line.strip().split(",") + if values[query_column] == query_value: + result.append(values[result_column]) + return result From 59e6a5b0d83f934b76a40519f813bfb803c14d7b Mon Sep 17 00:00:00 2001 From: Ashlyn Sloane Date: Tue, 1 Sep 2026 18:57:45 +0000 Subject: [PATCH 2/3] Update print_fires to use get_column --- print_fires.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/print_fires.py b/print_fires.py index 4992fb6..10fe7fe 100644 --- a/print_fires.py +++ b/print_fires.py @@ -1,6 +1,9 @@ +from my_utils import get_column + country='United States of America' -county_column = 1 -fires_column = 4 +country_column = 0 +fires_column = 3 file_name = 'Agrofood_co2_emission.csv' -fires = get_column() + +fires = get_column(file_name, country_column, country, fires_column) print(fires) From b529a4ee54afc8499b14b459383318d037955c3e Mon Sep 17 00:00:00 2001 From: Ashlyn Sloane Date: Tue, 1 Sep 2026 19:16:31 +0000 Subject: [PATCH 3/3] Add named result column and run script using run.sh --- README.md | 18 +++++++++++++++++- my_utils.py | 2 +- print_fires.py | 2 +- run.sh | 3 +++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 run.sh diff --git a/README.md b/README.md index 2d02f3f..d79259e 100644 --- a/README.md +++ b/README.md @@ -1 +1,17 @@ -# python-refresher \ No newline at end of file +# python-refresher + +This repository contains Python code for reading agricultural CO2 emissions data. + +### Changes ### +- Implemented "get_column()" in "my_utils.py" to read a file line-by-line and return values from a selected column +- Updated "get_column()" so that "result_column" defauls to column 1 +- Updated "print_fires.py" to print forest fire emissions for the United States +- Added "run.sh" to run "print_fires.py" + +### Running the Script ### + +Run the script with: + +bash run.sh + +The data file "Agrofood_co2_emission.csv" must be present in the repo directory but do not commit it to Git. diff --git a/my_utils.py b/my_utils.py index 2baa5f7..ad6d803 100644 --- a/my_utils.py +++ b/my_utils.py @@ -1,4 +1,4 @@ -def get_column(file_name, query_column, query_value, result_column): +def get_column(file_name, query_column, query_value, result_column=1): result = [] with open(file_name, "r") as file: diff --git a/print_fires.py b/print_fires.py index 10fe7fe..4d96c6a 100644 --- a/print_fires.py +++ b/print_fires.py @@ -5,5 +5,5 @@ fires_column = 3 file_name = 'Agrofood_co2_emission.csv' -fires = get_column(file_name, country_column, country, fires_column) +fires = get_column(file_name, country_column, country, result_column= fires_column) print(fires) diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..769760c --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +python print_fires.py