1# This action requires the 'csv' module
2import csv
3
4# The basic usage is to first define the rows of the csv file:
5row_list = [["SN", "Name", "Contribution"],
6 [1, "Linus Torvalds", "Linux Kernel"],
7 [2, "Tim Berners-Lee", "World Wide Web"],
8 [3, "Guido van Rossum", "Python Programming"]]
9
10# And then use the following to create the csv file:
11with open('protagonist.csv', 'w', newline='') as file:
12 writer = csv.writer(file)
13 writer.writerows(row_list)
14# This will create a csv file in the current directory
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 pandas as pd
2
3df = pd.read_csv (r'Path where the CSV file is stored\File name.csv')
4print (df)
5
1##text=List of strings to be written to file
2with open('csvfile.csv','wb') as file:
3 for line in text:
4 file.write(line)
5 file.write('\n')
6