18. CSV Flashcards
1
Q
with Open
A
use with resource and make sure it is close, like try escape
with open(‘Input/Covid.csv’, mode=’r’) as csv_file:
2
Q
DictReader(csv_file)
A
each row will be read as a separate dictionary creating a dictionary “set’. header will be read as dict key
3
Q
open read write mode
A
read: r
write: w
read/write: ‘r+’
4
Q
reader(csv_file)
A
reader splits each row on a specified delimiter and returns a list of strings; compare to Dictreader
use line count (count yourself) to split the header
5
Q
writer(csv_file)
A
change the whole file if it is w mode
6
Q
reading csv with two columns as dict
A
d = dict(reader)