csv
Read and write comma-separated files correctly (quoting, delimiters).
Beginner
import csv
with open("log.csv", newline="") as f:
for row in csv.DictReader(f):
print(row["time"], row["voltage"])
with open("out.csv", "w", newline="") as f:
w = csv.writer(f); w.writerow(["t", "v"]); w.writerows(rows)
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.