-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy3rd.py
More file actions
31 lines (25 loc) · 827 Bytes
/
my3rd.py
File metadata and controls
31 lines (25 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Column names and column indices to read
#columns = {'date': 0, 'time': 1, 'tempout': 3}
columns = {'date': 0, 'time': 1, 'tempout': 2, 'windspeed': 7}
# Data types for each column (only if non-string)
types = {'tempout': float, 'windspeed': float}
# Initialize my data variable
data = {}
for column in columns:
data[column] = []
# Read and parse the data file
filename = "data/wxobs20170821.txt"
with open(filename, 'r') as datafile:
# Read the first three lines (header)
for _ in range(3):
datafile.readline()
# Read and parse the rest of the file
for line in datafile:
split_line = line.split()
for column in columns:
i = columns[column]
t = types.get(column, str)
value = t(split_line[i])
data[column].append(value)
# DEBUG
print(data['tempout'])