Open zhap066 opened 1 year ago
def write_a_csv(timeseries, filename): Open the file for writing (w+) with open(filename, "w+") as file: Add a header to the file so people know what each column is print(f"#time[s],voltage[V]", file=file)
Loop over the rows and print them to the file
for t, d in zip(timeseries.times, timeseries.data):
print(f"{t},{d}", file=file)
write_a_csv(timeseries, "use_print_to_write_a_csv_example.csv") import csv
field names fields = ['Name', 'Branch', 'Year', 'CGPA']
data rows of csv file rows = [ ['Nikhil', 'COE', '2', '9.0'], ['Sanchit', 'COE', '2', '9.1'], ['Aditya', 'IT', '2', '9.3'], ['Sagar', 'SE', '1', '9.5'], ['Prateek', 'MCE', '3', '7.8'], ['Sahil', 'EP', '2', '9.1']]
name of csv file filename = "university_records.csv"
writing to csv file with open(filename, 'w') as csvfile: creating a csv writer object csvwriter = csv.writer(csvfile)
writing the fields
csvwriter.writerow(fields)
writing the data rows
csvwriter.writerows(rows)
https://packaging.python.org/en/latest/tutorials/packaging-projects/
11/11/2022 16:33
Collect together used sites in order to support code, create a reference page.