Every line of 'numpy to csv' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
88 def csv_to_numpy(string_like, dtype=None): # type: (str or unicode) -> np.array 89 """Convert a CSV object to a numpy array. 90 91 Args: 92 string_like (str): CSV string. 93 dtype (dtype, optional): Data type of the resulting array. If None, the dtypes will be determined by the 94 contents of each column, individually. This argument can only be used to 95 'upcast' the array. For downcasting, use the .astype(t) method. 96 Returns: 97 (np.array): numpy array 98 """ 99 stream = StringIO(string_like) 100 return np.genfromtxt(stream, dtype=dtype, delimiter=',')
80 def save2csv(traces): 81 to_csv = [] 82 for scenario_name, tracer in traces.iteritems(): 83 tmp = {'scenario_name': scenario_name, 84 'first_depletion': tracer['first_depletion'][2][0], 85 '30per_depletion': tracer['30per_depletion'][2][0]} 86 for trace_name, trace in tracer.iteritems(): 87 if not trace[4]: 88 continue 89 values = np.array(trace[2]) 90 mean = np.nanmean(values) 91 stdev = np.nanstd(values) 92 tmp[trace_name+ ' (mean)'] = mean 93 tmp[trace_name+ ' (stdev)'] = stdev 94 95 to_csv.append(tmp) 96 97 df = pd.DataFrame(to_csv) 98 dir_path = cf.RESULTS_PATH + time.strftime("%Y-%m-%d_%H:%M:%S") + '/' 99 os.makedirs(dir_path) 100 df.to_csv(dir_path + 'results_summary.csv')
20 def ToCsv(self,name='FileName.csv', DataToWrite=[ 21 ["First", "Second", "Third"], ]): 22 #Write DataResult to CSV file 23 with open(name, 'w', newline='') as fp: 24 a = csv.writer(fp, delimiter=',') 25 a.writerows(DataToWrite)
1153 def to_csv(self, file_name, sep=',', encoding=None): 1154 start = time.time() 1155 init = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss 1156 1157 self._data.to_csv(file_name, sep, encoding) 1158 1159 finish = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss 1160 self._last_operation_dict['time'] = time.time() - start 1161 self._last_operation_dict['name'] = 'to_csv' 1162 self._last_operation_dict['mem_usage'] = finish - init