1# pip install pandas
2import pandas as pd
3
4# Read the csv file
5data = pd.read_csv('data.csv')
6
7# Print it out if you want
8print(data)
1import csv
2
3with open('names.csv', 'w') as csvfile:
4 fieldnames = ['first_name', 'last_name']
5 writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
6
7 writer.writeheader()
8 writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})
9 writer.writerow({'first_name': 'Lovely', 'last_name': 'Spam'})
10 writer.writerow({'first_name': 'Wonderful', 'last_name': 'Spam'})
11
1import csv
2
3with open('example.csv') as csvfile:
4 readCSV = csv.reader(csvfile, delimiter=',')
1import csv
2with open('some.csv', newline='') as f:
3 reader = csv.reader(f)
4 for row in reader:
5 print(row)
6
1import pandas as pd # pip install pandas
2
3#read the CSV file
4data_file = =pd.read_csv('some_file.csv')
5print(data_file)
6
1>>> import csv
2>>> with open('eggs.csv', newline='') as csvfile:
3... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
4... for row in spamreader:
5... print(', '.join(row))
6Spam, Spam, Spam, Spam, Spam, Baked Beans
7Spam, Lovely Spam, Wonderful Spam
8