我有一个DML文件,其数据为:
record
string(" ") name;
decimal(" ") id;
decimal("\n") salary;
end
并且array1应该存储 姓名,身份证,工资
和一个数据文件,其数据为:
chinmoy 1 10000
Aakash 2 30000
ashish 3 40000
现在,array2应该存储: [chinmoy,1,10000],[aakash,2,30000],[ashish,3,40000]
现在,我想以多维方式创建一个包含数据的新数组,以便当我访问array(0)(0)时,它应该提供chinmoy
name id salary
chinmoy 1 10000
aakash 2 30000
ashish 3 40000
我尝试过这种方式,但是被卡住了,请帮帮我:
import numpy as np
test_data_file_name=open("data_file.txt")
test_data_info = test_data_file_name.readlines()
for line in test_data_info:
test_data_list = line.split(" ")
data_array = np.asarray(test_data_list)
print(data_array)
from itertools import takewhile,dropwhile
test_dml= {}
with open("dml_file.txt") as f:
starting_iterator = dropwhile(lambda x: x.strip() != 'record',f)
next(starting_iterator,None)
contents = takewhile(lambda x: x.strip() != 'end',starting_iterator)
a = list(contents)
for line in a:
(key,val) = line.split(")")
test_dml[key] = val
d = (list(test_dml.values()))
dml_array = np.asarray(d)
print(dml_array)