我有这个txt文件,其中包含存储的数据点:
fbbh-b-an86 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 138 138 138 138 138 138 138 138 138 138 138 138 138 138 71 71 71 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 71 71 71 71 71 71 71 71 71 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 138 138 138 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 1 1 1 1 1 1 1 1 1 1 1 38 38 38 38 38 38 38 38 38 16 16 16 16 32 32 32 32 32 32 32 32 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 84 84 84 84 84 136 136 136 136 136 136 136 123 123 123 123 123 123 123 1 1 1 1 1 1 1 1 50 50 50 50 50 50 50 50 50 50 50 50 50 50 115 115 115 115 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
fbbh-b-an87 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 42 42 42 42 42 92 92 92 92 92 92 116 116 116 116 116 116 116 47 47 47 47 47 47 47 47 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 110 68 68 68 68 68 68 68 80 80 80 111 111 111 111 114 114 114 114 114 114 114 114 123 123 123 123 123 123 123 123 123 123 123 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 107 107 107 107 107 107 107 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
fbbh-b-an88 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 66 66 66 108 108 108 108 108 108 108 108 108 52 52 52 52 111 111 111 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 114 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 50 50 50 50 50 50 35 35 35 35 35 35 35 35 35 35 35 35 35 35 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 55 55 55 55 55 55 55 55 55 55 1 1 1 1 1 1 1 1 1 1 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 54 54 54 54 54 54 54 54 54 54 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 127 127 127 127 127 127 127 1 1 1 1 1 1 1 1 138 138 138 138 138 138 138 138 138 138 68 68 68 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 108 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
开头的名称是与数据点关联的名称,数字是数据点。数据点的数量取决于名称,因此列数不相同。
我需要在numpy数组中按特定顺序存储这些数据集,我将它存储在地图中会使生活更轻松,因为我只需要根据名称进行查找以查找获取我需要的数据点集。但是如何用这样的文件做到这一点..
我试过这样的事情:
导入csv
data = open(data_points,"rb")
dict = csv.DictReader(data,delimiter=" ")
但是这导致None
出现,并且每个条目都无法根据名称查找..
{'': None, '115': None, '38': None, '16': None, 'fbbh-b-an86': 'fbbh-b-an87', '32': None, '50': None, '1': None, '123': None, '110': '110', '71': None, '138': '107', '84': None, '136': None}
{'': '1', '115': '29', '38': '1', '16': '1', 'fbbh-b-an86': 'fbbh-b-an88', '32': '1', '50': '29', '1': '1', '123': '55', '110': '101', '71': '35', '138': '114', None: ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '54', '54', '54', '54', '54', '54', '54', '54', '54', '54', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '127', '127', '127', '127', '127', '127', '127', '1', '1', '1', '1', '1', '1', '1', '1', '138', '138', '138', '138', '138', '138', '138', '138', '138', '138', '68', '68', '68', '108', '108', '108', '108', '108', '108', '108', '108', '108', '108', '108', '108', '108', '108', '108', '108', '99', '99', '99', '99', '99', '99', '99', '99', '99', '99', '99', '99', '99', '99', '99', '99', '99', '99', '99', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', ''], '84': '42', '136': '42'}
{'': '32', '115': '38', '38': '74', '16': '71', 'fbbh-b-an86': 'fbbh-b-an89', '32': '71', '50': '38', '1': '32', '123': '1', '110': '24', '71': '71', '138': '1', None: ['32', '32', '32', '32', '32', '16', '16', '16', '16', '16', '16', '16', '16', '16', '84', '84', '84', '136', '136', '136', '136', '136', '123', '123', '123', '1', '1', '1', '1', '1', '1', '1', '1', '30', '30', '30', '30', '30', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '71', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '110', '110', '110', '110', '110', '110', '110', '110', '110', '110', '110', '110', '110', '110', '110', '110', '110', '110', '110', '44', '44', '44', '44', '128', '128', '128', '128', '128', '16', '16', '16', '92', '92', '92', '92', '92', '116', '116', '116', '116', '71', '71', '71', '71', '71', '90', '90', '90', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '91', '91', '91', '91', '91', '91', '91', '91', '91', '91', '91', '91', '91', '54', '54', '54', '54', '54', '54', '54', '54', '54', '54', '68', '68', '68', '68', '56', '56', '56', '56', '56', '116', '116', '116', '116', '116', '116', '116', '116', '116', '116', '71', '71', '71', '71', '90', '90', '90', '90', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '28', '91', '91', '91', '91', '91', '91', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', ''], '84': '71', '136': '1'}
答案 0 :(得分:0)
这里的DictReader对我来说似乎不合适,因为你的数据并不是每列有意义的,而是每一行都有一个名字和一些任意数据。
你是否想要一张地图['fbbh-b-an86']给你第一行积分的地图?如果是这样,这应该可以解决问题:
import csv
map = {}
with open(data_points, 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=' ')
for row in reader:
name = row[0]
map[name] = row[1:]
print map