Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ncasuk/ncas-isc
Browse files Browse the repository at this point in the history
  • Loading branch information
eardkdw committed Nov 23, 2018
2 parents 1708bd6 + e7d8c2f commit 27e8c93
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Binary file modified overview_presentations/Parallel_Processing_Large_Data.pdf
Binary file not shown.
Binary file modified overview_presentations/Parallel_Processing_Large_Data.pptx
Binary file not shown.
56 changes: 56 additions & 0 deletions python/exercises/example_code/weather-reader-example-script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import sys


# Functions
def split_and_strip(line):
values = []

for value in line.split(","):
values.append(value.strip())

return values


def read_data_file(fpath):
"""
Reads weather data from CSV file.
Params:
- fpath: file path to CSV file
Returns:
- data dictionary.
"""
# Main code
data = {}

with open(fpath, 'r') as reader:

# Read header
header = reader.readline()
col_names = split_and_strip(header)

# Set up dictionary for loading
for col in col_names:
data[col] = []

# Read data
for line in reader:
data_items = split_and_strip(line)
print(f"[INFO] Data items: {data_items}")

for (index, item) in enumerate(data_items):
col = col_names[index]
value = item
data[col].append(value)

return data


if __name__ == "__main__":
# Call the function
args = sys.argv[1:]

for arg in args:

print("[INFO] Reading from: {}".format(arg))
data = read_data_file(arg)
print(data)

0 comments on commit 27e8c93

Please sign in to comment.