90. Working with CSV Files
1. Reading a CSV File
import csv
# Open the CSV file for reading
with open('data.csv', mode='r') as file:
reader = csv.reader(file)
for row in reader:
print(row)2. Reading CSV File with Headers
import csv
# Open the CSV file for reading with headers
with open('data.csv', mode='r') as file:
reader = csv.DictReader(file)
for row in reader:
print(row)3. Writing Data to a CSV File
4. Writing Data with Headers
5. Reading CSV File Line by Line
6. Skipping Header Row in CSV
7. Handling Comma-Separated Values with Different Delimiters
8. Writing CSV Data with Custom Delimiter
9. Reading CSV with Encoding
10. Handling Empty Rows in CSV Files
Last updated