import osfrom matplotlib import pyplot as pyplotfrom collections import defaultdictimport csvimport numpy as nppath = r'C:\Users\AK6PRAKT\Desktop\6daten'dirs = os.listdir(path) s = []x = []y = []names = []fig = pyplot.figure()for i in dirs: if os.path.splitext(i)[1] == ".csv": f = open(path+"/"+i) iter_f = iter(f); str = "" for line in iter_f: str = str + line s.append(str) with open(path+"/"+i,'r') as r: lines=r.readlines() with open(path+"/"+i,'w') as w: for row in lines: if 'Date' not in row: w.write(row) columns = defaultdict(list) with open(path+"/"+i) as f: reader = csv.reader(f) for row in reader: for (i,v) in enumerate(row): columns[i].append(v) list_temp1 = columns[0] list_temp1 = np.array(list_temp1) list_temp2 = columns[2] list_temp2 = np.array(list_temp2) print(list_temp1,list_temp2) y.append(float(list_temp2)) names.append(list_temp1)x = range(len(names))pyplot.ylim((0, 40)) my_y_ticks = np.arange(0, 40, 10)pyplot.plot(x,y, linewidth=2)pyplot.xticks(x,names,rotation = 90)fig = pyplot.figure(figsize=(10,10))pyplot.show()如果只有几个 csv 文件,此代码非常有效。但是我想在实践中应用这段代码,我需要分析超过200000个csv文件并制作一个图形,以便我可以清楚地看到这些数据的波动,但是当我想导入这些宏伟的文件时,出现以下错误:File "C:/Users/AK6PRAKT/headerremover.py", line 44, in <module>y.append(float(list_temp2))TypeError: only size-1 arrays can be converted to Python scalars我真的不知道解决这个问题,如果有人可以帮助我,非常感谢!!!!!!
添加回答
举报
0/150
提交
取消