我正在使用
需要将每个列拆分并指定给单独的
在迭代
到目前为止,我已经使用了以下代码,但我不想为每个
NumPy
的genfromtext
从CSV文件中获取列。需要将每个列拆分并指定给单独的
SQLAlchemy SystemRecord
,同时结合其他列和属性,并添加到数据库。在迭代
f1
到f9
列并将它们添加到会话对象 session object
中时,哪种做法最佳?到目前为止,我已经使用了以下代码,但我不想为每个
f
列做同样的事情:t = np.genfromtxt(FILE_NAME,dtype=[(np.str_, 20),(np.str_, 20),(np.str_, 20),(np.str_, 20),(np.str_, 20),(np.str_, 20),(np.str_, 20),(np.str_, 20), (np.str_, 20), (np.str_, 20),(np.str_, 20)]\
,delimiter=',',filling_values="None", skiprows=0,usecols=(0,1,2,3,4,5,6,7,8,9,10))
for r in enumerate(t):
_acol = r['f1'].split('-')
_bcol = r['f2'].split('-')
....
arec = t_SystemRecords(first=_acol[0], second=_acol[1], third=_acol[2], ... )
db.session.add(arec)
db.session.commit()
t
的转置,只需使用:for col in t.T: ...
? - Saullo G. P. Castrogenfromtxt
生成一个一维结构化数组。transpose
没有任何效果。 - hpaulj