我制作了一个Python程序来遍历数据的csv文件并生成一个新的csv文件。为了减少运行时间,我尝试使用numba,下面是我的代码:
import csv
import timeit
from numba import jit
@jit(nopython=True)
def main():
file = open("test_data.csv","r")
newfile = open("rewrite5_gpu_output.csv",'w', newline='')
writer = csv.writer(newfile)
dataframe = []
start = timeit.default_timer()
for line in file:
new_line = []
line = line.split(",")
for item in line:
if item == '\n':
pass
elif item == "active":
new_line.append(1) # 1 = active p53
elif item == "inactive":
new_line.append(0) # 0 = inactive p53
else:
try:
item = item.strip('\n')
item = float(item)
new_line.append(item)
except:
pass
dataframe.append(new_line)
#print(new_line)
writer.writerows(dataframe)
newfile.close()
stop = timeit.default_timer()
print('Time: ', stop - start)
main()
但是,我得到了错误:
AssertionError: Failed in nopython mode pipeline (step: analyzing bytecode)
SETUP_EXCEPT(arg=32, lineno=23)
答案 0 :(得分:0)
尝试注释掉“ try:”和“ except:”。 在其他文章中,我读到了try-numba.jit不支持 它可以在我的python脚本中工作。
br