-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader.py
executable file
·40 lines (31 loc) · 1.06 KB
/
reader.py
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
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
import csv
import pandas as pd
def read_csv(data_path, file_name):
extension = ".csv"
path = data_path + file_name + extension
print("### Reading " + path)
index = 0
with open(path, newline='') as f:
#reader = csv.reader(f, delimiter=',')
reader = pd.read_csv(path)
reader.set_index("DRAW NUMBER", inplace=True)
for row in reader:
print(', '.join(row))
index += 1
row_count = sum(1 for row in reader)
print("Read " + str(index) + " lines")
return reader
def read_last_line(data_path, file_name):
extension = ".csv"
path = data_path + file_name + extension
print("### Reading " + path)
with open(path, newline='') as f:
reader = csv.reader(f, delimiter=',')
row_count = sum(1 for row in reader)
print("File has " + str(row_count) + " lines")
skip = row_count - 1
df = pd.read_csv(path, skiprows=skip, usecols=[1])
print(df)
draw_number = df.iat[0, 0]
print("Most recent Draw # is " + str(draw_number))