PYTHON ADD DATA TO CSV code example

Example 1: append to csv python

with open('document.csv','a') as fd:
    fd.write(myCsvRow)

Example 2: python save as csv

import numpy as np
np.savetxt('data.csv', (col1_array, col2_array, col3_array), delimiter=',')

Example 3: writerows to existing csv python

import sys 
import os
import csv

listOfLines= [['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']]

def write_to_csv(list_of_emails):
   with open('emails.csv', 'w', newline='') as csvfile:
       writer = csv.writer(csvfile, delimiter = ',')
       writer.writerows(list_of_emails)

write_to_csv(listOfLines)