1import pandas as pd
2
3list1 = [1,2,3,4,5]
4df = pd.DataFrame(list1)
5df.to_csv('filename.csv', index=False)
6
7#index =false removes unnecessary indexing/numbering in the csv
1import csv
2
3with open('file.csv', newline='') as f:
4 reader = csv.reader(f)
5 data = list(reader)
6
7print(data)
8
1import csv
2with open('records.csv', 'r') as f:
3 file = csv.reader(f)
4 my_list = list(file)
5print(my_list)
1import csv
2
3with open("out.csv", "w", newline="") as f:
4 writer = csv.writer(f)
5 writer.writerows(a)
1# Convert a list into rows for a column in csv
2
3import csv
4for_example = [1, 2, 3, 4, 5, 6]
5with open('output.csv', 'w', newline='') as csv_1:
6 csv_out = csv.writer(csv_1)
7 csv_out.writerows([for_example[index]] for index in range(0, len(for_example)))
8
1import pandas as pd
2
3list1 = [1,2,3,4,5]
4df = pd.DataFrame(list1)
5df.to_csv('test.csv') ##It will include index also
6
7df.to_csv('test.csv', index=False) #Without Index