Every line of 'python write array 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.
50 def write_row(self, array): 51 """ 52 write a row into the file 53 """ 54 self.writer.writerow(array)
75 def writecsv(filename, rows, separator="\t", encoding="utf-8-sig"): 76 """Write the rows to the file. 77 78 :param filename: (str) 79 :param rows: (list) 80 :param separator: (str): 81 :param encoding: (str): 82 83 """ 84 with codecs.open(filename, "w+", encoding) as f: 85 for row in rows: 86 tmp = [] 87 for s in row: 88 if isinstance(s, (float, int)): 89 s = str(s) 90 else: 91 s = '"%s"' % s 92 tmp.append(s) 93 f.write('%s\n' % separator.join(tmp))
67 def write_csv(writer, data): 68 writer.writerow(data)
163 def write2csv(path, headers, rows): 164 with open(path, 'w', newline='') as file: 165 f_csv = csv.DictWriter(file, headers) 166 f_csv.writeheader() 167 f_csv.writerows(rows)
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)
11 def read_csv(array, filename): 12 with open(filename, 'rb') as input_file: 13 foo = csv.reader(input_file) 14 for row in foo: 15 array.append(row) 16 return array
72 def writeToCSV(dataToWrite, outputFileName): 73 with open(outputFileName, 'w') as csvfile: 74 w = csv.writer(csvfile, delimiter=',') 75 w.writerow(['song','pitch','diatonicNumber','beat','beatStrength','duration','IPA','vowelCategory','stress']) 76 for row in dataToWrite: 77 w.writerow(row) 78 print outputFileName, 'successfully created.'
51 def write_csv(data): 52 if not os.path.isfile(FILE_PATH): 53 file = open(FILE_PATH, "a") 54 with file: 55 writer = csv.DictWriter(file, fieldnames=data) 56 writer.writeheader() 57 58 unique_id = data["email"] 59 if duplicate_check(unique_id, FILE_PATH): 60 return 61 62 file = open(FILE_PATH, "a") 63 with file: 64 writer = csv.DictWriter(file, fieldnames=data) 65 writer.writerow(data)
144 def write_matrix(matrix, csv_filename=None): 145 with open(csv_filename, "w") as csv_file: 146 matrix.tofile(csv_file)
48 def save_nparray_to_csv_file(folder, filename, nparray, sep=','): 49 """ 50 Writes numpy array to csv file. 51 52 :param folder: Relative path to to folder. 53 :type folder: str 54 55 :param filename: Name of the file. 56 :type filename: str 57 58 :param nparray: Numpy array. 59 60 :param sep: Separator (DEFAULT: ',') 61 """ 62 # Make sure folder exists. 63 os.makedirs(os.path.dirname(os.path.expanduser(folder) +'/'), exist_ok=True) 64 65 name = os.path.join(os.path.expanduser(folder), filename) 66 print(name) 67 68 # Write array to file, separate elements with commas. 69 nparray.tofile(name, sep=sep, format="%s")