Autosave: 2024-04-28 12:30:05
This commit is contained in:
parent
a9d90823f7
commit
0d4675f055
2 changed files with 26 additions and 2 deletions
BIN
.zk/notebook.db
BIN
.zk/notebook.db
Binary file not shown.
|
@ -2,11 +2,35 @@
|
||||||
id: sgtn
|
id: sgtn
|
||||||
title: Working_with_CSVs_in_Python
|
title: Working_with_CSVs_in_Python
|
||||||
tags: []
|
tags: []
|
||||||
created: Sunday, April 28, 2024
|
created: Sunday, April 28, 2024
|
||||||
---
|
---
|
||||||
|
|
||||||
# Working_with_CSVs_in_Python
|
# Working_with_CSVs_in_Python
|
||||||
|
|
||||||
|
## Core package
|
||||||
|
|
||||||
## Related notes
|
```py
|
||||||
|
import csv
|
||||||
|
```
|
||||||
|
|
||||||
|
## Read and write to CSV
|
||||||
|
|
||||||
|
### Read
|
||||||
|
|
||||||
|
Use standard Pythonic "read" syntax:
|
||||||
|
|
||||||
|
```py
|
||||||
|
with open('./path.csv', mode="r") as csv_file:
|
||||||
|
reader = csv.reader(csv_file)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Write
|
||||||
|
|
||||||
|
Use standard Pythonic "read" syntax:
|
||||||
|
|
||||||
|
```py
|
||||||
|
with open('./new_csv_file.csv', mode="w") as csv_file:
|
||||||
|
write = csv.writer(csv_file)
|
||||||
|
```
|
||||||
|
|
||||||
|
The above will create the file as well, it doesn't need to be pre-existing.
|
||||||
|
|
Loading…
Add table
Reference in a new issue