how to create csv in python code example
Example 1: create csv file python
import csv
row_list = [["SN", "Name", "Contribution"],
[1, "Linus Torvalds", "Linux Kernel"],
[2, "Tim Berners-Lee", "World Wide Web"],
[3, "Guido van Rossum", "Python Programming"]]
with open('protagonist.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(row_list)
Example 2: python write csv line by line
with open('csvfile.csv','wb') as file:
for line in text:
file.write(line)
file.write('\n')
Example 3: import csv file in python
import pandas as pd
df = pd.read_csv (r'Path where the CSV file is stored\File name.csv')
print (df)