Dec-11-2018, 02:42 PM
I have a file with the following. It is delimited with tabs
I want to import into a python dictionary name data{} and name the keys as rid, rdate, rtype, rhist, rscan.
here is what I have so far. It imports the file
How can I import the file with the predefined keys?
Thanks
Quote:132 2018/07/28 01:41 0 141
133 2018/07/28 01:56 0 133
134 2018/07/28 02:11 0 126
135 2018/07/28 02:27 1 123
137 2018/07/28 02:27 0 126
138 2018/07/28 02:42 0 119
139 2018/07/28 02:57 0 96
140 2018/07/28 03:12 0 79
141 2018/07/28 03:27 0 71
142 2018/07/28 03:42 0 69
143 2018/07/28 03:57 0 72
I want to import into a python dictionary name data{} and name the keys as rid, rdate, rtype, rhist, rscan.
here is what I have so far. It imports the file
import csv with open('summary2.txt') as f: reader = csv.DictReader(f) data = [r for r in reader] print(data) [OrderedDict([('132\t2018/07/28 01:41\t0\t141', '133\t2018/07/28 01:56\t0\t133')]), OrderedDict([('132\t2018/07/28 01:41\t0\t141', '134\t2018/07/28 02:11\t0\t126')]), OrderedDict([('132\t2018/07/28 01:41\t0\t141', '135\t2018/07/28 02:27\t1\t\t123')]), OrderedDict([('132\t2018/07/28 01:41\t0\t141', '137\t2018/07/28 02:27\t0\t126')]), OrderedDict([('132\t2018/07/28 01:41\t0\t141', '138\t2018/07/28 02:42\t0\t119')]), OrderedDict([('132\t2018/07/28 01:41\t0\t141', '139\t2018/07/28 02:57\t0\t96')]), OrderedDict([('132\t2018/07/28 01:41\t0\t141', '140\t2018/07/28 03:12\t0\t79')]), OrderedDict([('132\t2018/07/28 01:41\t0\t141', '141\t2018/07/28 03:27\t0\t71')]), OrderedDict([('132\t2018/07/28 01:41\t0\t141', '142\t2018/07/28 03:42\t0\t69')]), OrderedDict([('132\t2018/07/28 01:41\t0\t141', '143\t2018/07/28 03:57\t0\t72')])]
How can I import the file with the predefined keys?
Thanks