我有以下蛮力代码:
import csv
d = {}
with open(csv_filename, 'r') as csv_file:
reader = csv.reader(csv_file)
for row in reader:
key = row[0]
d[key] = np.array(
[[float(x) for x in row[1:4]], [float(x) for x in row[4:7]],
[float(x) for x in row[7:]]], dtype=float)
是否有一种方法可以重写它以避免[1:4], [4:7]
等?
答案 0 :(得分:1)
如果我理解正确,则只需要重塑数据即可。
{"nr": "test_nr", "epoch_timestamp":"1557114198", "value":[1200,2300,5400,1200]} and so on..