Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Agrofood_co2_emission.csv
__pycache__/
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# python-refresher
# 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.
11 changes: 9 additions & 2 deletions my_utils.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
def get_column(file_name, query_column, query_value, result_column):
return None
def get_column(file_name, query_column, query_value, result_column=1):
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
9 changes: 6 additions & 3 deletions print_fires.py
Original file line number Diff line number Diff line change
@@ -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, result_column= fires_column)
print(fires)
3 changes: 3 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python print_fires.py