CSVファイルを一気読みじゃなく行毎に処理していく

pythonCSV ライブラリを使う

とりあえず、1行毎に読み込む

import csv
with open('data.csv', newline='') as f:
    reader = csv.reader(f)
    i = 0
    for row in reader:
        print(i,row)
        i = i+1
0 ['ZXC system log format ver.1']
1 ['date 2019/05/01 00:00:01']
2 ['Format', 'x', 'y', 'color']
3 ['12', '8', '8', '1']
4 ['1', '2', '3', '4', '5', '6', '7', '8']
5 ['1', '2', '3', '4', '5', '6', '7', '8']
6 ['1', '2', '3', '4', '5', '6', '7', '8']
7 ['1', '2', '3', '4', '5', '6', '7', '8']
8 ['1', '2', '3', '4', '5', '6', '7', '8']
9 ['1', '2', '3', '4', '5', '6', '7', '8']
10 ['1', '2', '3', '4', '5', '6', '7', '8']
11 ['1', '2', '3', '4', '5', '6', '7', '8']
12 []
13 ['ZXC system log format ver.1']
14 ['date 2019/05/02 00:00:01']
15 ['Format', 'x', 'y', 'color']
16 ['12', '8', '8', '2']
17 ['8', '1', '2', '3', '4', '5', '6', '7']
18 ['8', '1', '2', '3', '4', '5', '6', '7']
19 ['8', '1', '2', '3', '4', '5', '6', '7']
20 ['8', '1', '2', '3', '4', '5', '6', '7']
21 ['8', '1', '2', '3', '4', '5', '6', '7']
22 ['8', '1', '2', '3', '4', '5', '6', '7']
23 ['8', '1', '2', '3', '4', '5', '6', '7']
24 ['8', '1', '2', '3', '4', '5', '6', '7']
25 []
26 ['ZXC system log format ver.1']
27 ['date 2019/05/03 00:00:01']
28 ['Format', 'x', 'y', 'color']
29 ['12', '8', '8', '3']
30 ['7', '8', '1', '2', '3', '4', '5', '6']
31 ['7', '8', '1', '2', '3', '4', '5', '6']
32 ['7', '8', '1', '2', '3', '4', '5', '6']
33 ['7', '8', '1', '2', '3', '4', '5', '6']
34 ['7', '8', '1', '2', '3', '4', '5', '6']
35 ['7', '8', '1', '2', '3', '4', '5', '6']
36 ['7', '8', '1', '2', '3', '4', '5', '6']
37 ['7', '8', '1', '2', '3', '4', '5', '6']
38 []
39 ['ZXC system log format ver.1']
40 ['date 2019/05/04 00:00:01']
41 ['Format', 'x', 'y', 'color']
42 ['12', '8', '8', '4']
43 ['6', '7', '8', '1', '2', '3', '4', '5']
44 ['6', '7', '8', '1', '2', '3', '4', '5']
45 ['6', '7', '8', '1', '2', '3', '4', '5']
46 ['6', '7', '8', '1', '2', '3', '4', '5']
47 ['6', '7', '8', '1', '2', '3', '4', '5']
48 ['6', '7', '8', '1', '2', '3', '4', '5']
49 ['6', '7', '8', '1', '2', '3', '4', '5']
50 ['6', '7', '8', '1', '2', '3', '4', '5']
51 []
52 ['ZXC system log format ver.1']
53 ['date 2019/05/05 00:00:01']
54 ['Format', 'x', 'y', 'color']
55 ['12', '8', '8', '5']
56 ['5', '6', '7', '8', '1', '2', '3', '4']
57 ['5', '6', '7', '8', '1', '2', '3', '4']
58 ['5', '6', '7', '8', '1', '2', '3', '4']
59 ['5', '6', '7', '8', '1', '2', '3', '4']
60 ['5', '6', '7', '8', '1', '2', '3', '4']
61 ['5', '6', '7', '8', '1', '2', '3', '4']
62 ['5', '6', '7', '8', '1', '2', '3', '4']
63 ['5', '6', '7', '8', '1', '2', '3', '4']
64 []
65 ['ZXC system log format ver.1']
66 ['date 2019/05/06 00:00:01']
67 ['Format', 'x', 'y', 'color']
68 ['12', '8', '8', '6']
69 ['4', '5', '6', '7', '8', '1', '2', '3']
70 ['4', '5', '6', '7', '8', '1', '2', '3']
71 ['4', '5', '6', '7', '8', '1', '2', '3']
72 ['4', '5', '6', '7', '8', '1', '2', '3']
73 ['4', '5', '6', '7', '8', '1', '2', '3']
74 ['4', '5', '6', '7', '8', '1', '2', '3']
75 ['4', '5', '6', '7', '8', '1', '2', '3']
76 ['4', '5', '6', '7', '8', '1', '2', '3']
77 []
78 ['ZXC system log format ver.1']
79 ['date 2019/05/07 00:00:01']
80 ['Format', 'x', 'y', 'color']
81 ['12', '8', '8', '7']
82 ['3', '4', '5', '6', '7', '8', '1', '2']
83 ['3', '4', '5', '6', '7', '8', '1', '2']
84 ['3', '4', '5', '6', '7', '8', '1', '2']
85 ['3', '4', '5', '6', '7', '8', '1', '2']
86 ['3', '4', '5', '6', '7', '8', '1', '2']
87 ['3', '4', '5', '6', '7', '8', '1', '2']
88 ['3', '4', '5', '6', '7', '8', '1', '2']
89 ['3', '4', '5', '6', '7', '8', '1', '2']
90 []
91 ['ZXC system log format ver.1']
92 ['date 2019/05/08 00:00:01']
93 ['Format', 'x', 'y', 'color']
94 ['12', '8', '8', '8']
95 ['2', '3', '4', '5', '6', '7', '8', '1']
96 ['2', '3', '4', '5', '6', '7', '8', '1']
97 ['2', '3', '4', '5', '6', '7', '8', '1']
98 ['2', '3', '4', '5', '6', '7', '8', '1']
99 ['2', '3', '4', '5', '6', '7', '8', '1']
100 ['2', '3', '4', '5', '6', '7', '8', '1']
101 ['2', '3', '4', '5', '6', '7', '8', '1']
102 ['2', '3', '4', '5', '6', '7', '8', '1']
103 []

読み込んだデータがすべて文字列になってしまうので個別にデコードする

import csv
with open('data.csv', newline='') as f:
    reader = csv.reader(f)
    i=1
    for row in reader:
        if len(row) == 0 :
            print(i,[])  # 改行だけのとき
        else:
            if row[0][0] in "-+0123456789" and row[0][1:].isnumeric() : # 数値の時
                print(i,[int(x_int) for x_int in row])
            else:
                try: # 小数点チェック
                        float(row[0])
                except ValueError: # NGの時は文字列
                    print(i,row)
                else:
                    print(i,[float(x) for x in row])
        i=i+1
1 ['ZXC system log format ver.1']
2 ['date 2019/05/01 00:00:01']
3 ['Format', 'x', 'y', 'color']
4 [1.01, 8.0, 8.0, 1.0]
5 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
6 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
7 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
8 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
9 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
10 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
11 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
12 []
13 ['ZXC system log format ver.1']
14 ['date 2019/05/02 00:00:01']
15 ['Format', 'x', 'y', 'color']
16 [1.01, 8.0, 8.0, 2.0]
17 [8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
18 [8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
19 [8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
20 [8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
21 [8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
22 [8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
23 [8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
24 [8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
25 []
26 ['ZXC system log format ver.1']
27 ['date 2019/05/03 00:00:01']
28 ['Format', 'x', 'y', 'color']
29 [1.01, 8.0, 8.0, 3.0]
30 [7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
31 [7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
32 [7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
33 [7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
34 [7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
35 [7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
36 [7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
37 [7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
38 []
39 ['ZXC system log format ver.1']
40 ['date 2019/05/04 00:00:01']
41 ['Format', 'x', 'y', 'color']
42 [1.01, 8.0, 8.0, 4.0]
43 [6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0]
44 [6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0]
45 [6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0]
46 [6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0]
47 [6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0]
48 [6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0]
49 [6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0]
50 [6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0, 5.0]
51 []
52 ['ZXC system log format ver.1']
53 ['date 2019/05/05 00:00:01']
54 ['Format', 'x', 'y', 'color']
55 [1.01, 8.0, 8.0, 5.0]
56 [5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0]
57 [5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0]
58 [5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0]
59 [5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0]
60 [5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0]
61 [5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0]
62 [5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0]
63 [5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0, 4.0]
64 []
65 ['ZXC system log format ver.1']
66 ['date 2019/05/06 00:00:01']
67 ['Format', 'x', 'y', 'color']
68 [1.01, 8.0, 8.0, 6.0]
69 [4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0]
70 [4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0]
71 [4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0]
72 [4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0]
73 [4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0]
74 [4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0]
75 [4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0]
76 [4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0, 3.0]
77 []
78 ['ZXC system log format ver.1']
79 ['date 2019/05/07 00:00:01']
80 ['Format', 'x', 'y', 'color']
81 [1.01, 8.0, 8.0, 7.0]
82 [3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0]
83 [3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0]
84 [3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0]
85 [3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0]
86 [3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0]
87 [3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0]
88 [3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0]
89 [3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0, 2.0]
90 []
91 ['ZXC system log format ver.1']
92 ['date 2019/05/08 00:00:01']
93 ['Format', 'x', 'y', 'color']
94 [1.01, 8.0, 8.0, 8.0]
95 [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0]
96 [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0]
97 [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0]
98 [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0]
99 [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0]
100 [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0]
101 [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0]
102 [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 1.0]
103 []

初めからデータ構造が分かっているなら個別にデコードことも可能

上記の例で作るとするとこんな感じ drive.google.com

tiffで行うとこんな感じ? read_tiff.py - Google ドライブ