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:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

open read write mode

A

read: r
write: w
read/write: ‘r+’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

writer(csv_file)

A

change the whole file if it is w mode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

reading csv with two columns as dict

A

d = dict(reader)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly